move code up one directory
[atutor.git] / jscripts / ATutorContentMenu.js
1 /* 
2 ATutor
3 Copyright (c) 2002 - 2010
4 Inclusive Design Institute
5 http://atutor.ca
6
7 This program is free software. You can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation.
10 */
11
12 /* Note that this javascript calls on a js function ATutor.course.contentMenu.initContentMenu()
13 that is generated from php function getInitMenuJS() in ContentManager.class.php. So, must call 
14 the php function before including this js script. */
15
16 /* global jQuery */
17
18 var ATutor = ATutor || {};
19 ATutor.course = ATutor.course || {};
20 ATutor.course.contentMenu = ATutor.course.contentMenu || {};
21
22 (function() {
23
24         var inlineEditsSetup = function () {
25                 jQuery("#editable_table").find(".inlineEdits").each(function() {
26                         jQuery(this).text(jQuery(this).attr("title"));
27                 });
28                 
29                 var tableEdit = fluid.inlineEdits("#editable_table", {
30                         selectors : {
31                                 text : ".inlineEdits",
32                                 editables : "span:has(span.inlineEdits)"
33                         },
34                         defaultViewText: "",
35                         applyEditPadding: false,
36                         useTooltip: false,
37                         listeners: {
38                                 afterFinishEdit : function (newValue, oldValue, editNode, viewNode) {
39                                         if (newValue != oldValue) 
40                                         {
41                                                 rtn = jQuery.post(ATutor.base_path+"mods/_core/content/menu_inline_editor_submit.php", { "field":viewNode.id, "value":newValue }, 
42                                                                   function(data) {}, "json");
43                                         }
44                                 }
45                         }
46                 });
47
48                 jQuery(".fl-inlineEdit-edit").css("width", "80px")
49         };
50
51         ATutor.course.contentMenu.expandContentFolder = function(contentID) {
52                 jQuery("#folder"+contentID).show();
53                 jQuery("#tree_icon"+contentID).attr("src", ATutor.course.collapse_icon);
54                 jQuery("#tree_icon"+contentID).attr("alt", ATutor.course.text_collapse);
55                 jQuery("#tree_icon"+contentID).attr("title", ATutor.course.text_collapse);
56         };
57
58         ATutor.course.contentMenu.collapseContentFolder = function(contentID) {
59                 jQuery("#folder"+contentID).hide();
60                 jQuery("#tree_icon"+contentID).attr("src", ATutor.course.expand_icon);
61                 jQuery("#tree_icon"+contentID).attr("alt", ATutor.course.text_expand);
62                 jQuery("#tree_icon"+contentID).attr("title", ATutor.course.text_expand);
63         };
64
65         ATutor.course.contentMenu.switchEditMode = function() {
66                 title_edit = ATutor.course.text_enter_edit_mode;
67                 img_edit = ATutor.base_path+"images/medit.gif";
68                 
69                 title_view = ATutor.course.text_exit_edit_mode;
70                 img_view = ATutor.base_path+"images/mlock.gif";
71                 
72                 if (jQuery("#img_switch_edit_mode").attr("src") == img_edit)
73                 {
74                         jQuery("#img_switch_edit_mode").attr("src", img_view);
75                         jQuery("#img_switch_edit_mode").attr("alt", title_view);
76                         jQuery("#img_switch_edit_mode").attr("title", title_view);
77                         inlineEditsSetup();
78                 }
79                 else
80                 { // refresh the content navigation to exit the edit mode
81                         jQuery.post(ATutor.base_path+"mods/_core/content/refresh_content_nav.php", {}, 
82                                                 function(data) {jQuery("#editable_table").replaceWith(data); ATutor.course.contentMenu.initContentMenu();});
83                 }
84         };
85
86         jQuery(document).ready(function () {
87                 ATutor.course.contentMenu.initContentMenu();
88         });
89 })();