Created
June 19, 2009 09:32
-
-
Save deepakprasanna/132530 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
var doc_helpers = {}; | |
doc_helpers.initialized = false; | |
doc_helpers.init = function(el) | |
{ | |
$.ajax({url: '/sections/', | |
error: function(xmlHttpRequest, text, excp){ | |
console.log("An error occured while getting /sections/"); | |
}, | |
success: function(data, textStatus){ | |
$(el).html(data); | |
$('#new_section_link').href="#"; | |
$('#new_section_link').click(function(e){ | |
$.get('/sections/new', {}, function(data,stat){ | |
$('#new_section_dialog').html(data).dialog({title: "Create a section", modal: true}); | |
$('#new_section').ajaxForm({target: '#new_section_dialog', | |
success: function(content){ | |
if($('#errorExplanation')){ return false; } | |
alert("Form submitted"); | |
$('#new_section_dialog').dialog("close"); | |
doc_helpers.init($('#folder_tree')); | |
}}); | |
}) | |
return false; | |
}); | |
$('#sections').layout(); | |
$('#sections_accordion').accordion({active: false, | |
autoHeight: false, | |
navigation: true, | |
header: "h3", | |
change: function(event, ui){ | |
location.href=$(ui.newHeader).find('a')[0].href; | |
} | |
}); | |
if(doc_helpers.current_section_id) | |
{ | |
$($('#section'+doc_helpers.current_section_id).find('h3')[0]).click(); | |
doc_helpers.draw_tree(doc_helpers.current_section_id); | |
} | |
doc_helpers.initialized = true; | |
}}); | |
} | |
doc_helpers.draw_tree = function(section_id) | |
{ | |
var tree=new Array(); | |
var treediv=$('#tree-'+section_id); | |
if(treediv.find('ul.ltr').length>0){return;} | |
treediv.tree({path: '/', | |
data: {type: 'xml_flat', | |
async: true, | |
url: '/sections/'+section_id+'.xml', | |
}, | |
ui: { | |
theme_path: '/stylesheets/themes/', | |
theme_name: 'classic'}, | |
callback: { | |
onopen: function(node, tree){ | |
console.log(node); | |
}}}); | |
} | |
var tree_app = new Sammy.Application(function() { with(this) { | |
debug = true; | |
element_selector = '#folder_tree'; | |
get('#/', function() { with(this) { | |
if(!doc_helpers.initialized) { doc_helpers.init($element()); } | |
}}); | |
get('#/section/:id', function() { with(this) { | |
var section_id=params['id']; | |
if(!doc_helpers.initialized) | |
{ | |
doc_helpers.current_section_id=+params['id']; | |
doc_helpers.init($element()); | |
} | |
$($('#section'+section_id).find('h3')[0]).click(); | |
doc_helpers.draw_tree(section_id); | |
}}); | |
}}); | |
var main_app = new Sammy.Application(function() { with(this) { | |
debug = true; | |
element_selector = '#main'; | |
get('#/', function() { with(this) { | |
$element().text("inserted by sammy"); | |
}}); | |
get('#/section/:id', function() { with(this) { | |
partial('/sections/'+params['id'], function(data) | |
{ | |
$element().html(data); | |
}); | |
//$element().text("Section show and edit comes here for " + params['id']); | |
}}); | |
}}); | |
$(function() { | |
tree_app.run('#/'); | |
main_app.run('#/'); | |
}); | |
})(jQuery); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment