diff options
author | Jayaram Pai | 2014-04-26 14:54:09 +0530 |
---|---|---|
committer | Jayaram Pai | 2014-04-26 14:54:09 +0530 |
commit | 430133242f89015f4ffc500fb34eedf2324ec3a1 (patch) | |
tree | c1a3dadd857a61576176876e2a045b38559b282f /js/scilab_fixer.js | |
download | scilab_fixer-430133242f89015f4ffc500fb34eedf2324ec3a1.tar.gz scilab_fixer-430133242f89015f4ffc500fb34eedf2324ec3a1.tar.bz2 scilab_fixer-430133242f89015f4ffc500fb34eedf2324ec3a1.zip |
initial commit
Diffstat (limited to 'js/scilab_fixer.js')
-rw-r--r-- | js/scilab_fixer.js | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/js/scilab_fixer.js b/js/scilab_fixer.js new file mode 100644 index 0000000..43450f3 --- /dev/null +++ b/js/scilab_fixer.js @@ -0,0 +1,117 @@ +$(document).ready(function() { + var basePath = Drupal.settings.basePath; + var modPath = basePath + "fix/"; + + $category = $("#fix-caption-form #edit-category"); + $book = $("#fix-caption-form #edit-book"); + $chapter = $("#fix-caption-form #edit-chapter"); + $example = $("#fix-caption-form #edit-example"); + $caption = $("#fix-caption-form #edit-caption"); + $code = $("#fix-caption-form #fix-caption-code"); + $form = $("#scilab-fixer-caption-form"); + $updating = $("#fix-caption-page #updating"); + $done = $("#fix-caption-page #done"); + + function reset() { + for (var i = 0, l = arguments.length; i < l; i ++) { + switch(arguments[i]) { + case "book": + $book.html("<option value='0'>Please select a book</option>"); + break; + + case "chapter": + $chapter.html("<option value='0'>Please select a chapter</option>"); + break; + + case "example": + $example.html("<option value='0'>Please select a example</option>"); + break; + + } + } + } + + $category.change(function() { + reset("book", "chapter", "example"); + var category_id = $(this).val(); + + $.ajax({ + url: modPath + "ajax/category/" + category_id, + type: "POST", + dataType: "html", + success: function(data) { + $book.html(data); + } + }); + }); + + $book.change(function() { + reset("chapter", "example"); + var book_id = $(this).val(); + + $.ajax({ + url: modPath + "ajax/book/" + book_id, + type: "POST", + dataType: "html", + success: function(data) { + $chapter.html(data); + } + }); + }); + + $chapter.change(function() { + reset("example"); + var chapter_id = $(this).val(); + + $.ajax({ + url: modPath + "ajax/chapter/" + chapter_id, + type: "POST", + dataType: "html", + success: function(data) { + $example.html(data); + } + }); + }); + + $example.change(function() { + var example_id = $(this).val(); + + $.ajax({ + url: modPath + "ajax/example/" + example_id, + type: "POST", + dataType: "html", + success: function(data) { + var code = $(data).filter("#code").html(); + $code.html(code); + var caption = $(data).filter("#caption").html(); + $caption.val(caption); + } + }); + }); + + $form.submit(function(e) { + var example_id = $example.val(); + if(example_id != "0") { + var caption = $caption.val(); + $updating.show(); + $.ajax({ + url: modPath + "ajax/update/", + type: "POST", + data: { + example_id: example_id, + caption: caption + }, + dataType: "html", + success: function(data) { + $chapter.trigger("change"); + $updating.hide(); + $done.show(); + $done.fadeOut("slow"); + } + }); + } else { + alert("No example selected.") + } + e.preventDefault(); + }); +}); |