PluginProbe
CSS & JavaScript Toolbox / 8.0.2
CSS & JavaScript Toolbox v8.0.2
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
css-javascript-toolbox / views / blocks / block / public / js / codefile / codefile.js

codefile.js in CSS & JavaScript Toolbox 8.0.2, at views/blocks/block/public/js/codefile/codefile.js

140 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 *
3 *
4 *
5 *
6 */
7
8 /**
9 *
10 *
11 *
12 */
13 (function($) {
14
15 /**
16 * put your comment there...
17 *
18 * @param block
19 */
20 CJTBlockFile = function(block) {
21
22 /**
23 * put your comment there...
24 *
25 * @type Object
26 */
27 this.file = {};
28
29 /**
30 * put your comment there...
31 *
32 *
33 */
34 var _onclickfilename = function(event) {
35 // Switch Code Files Managed to current block.
36 CJTBlockCodeFileView.switchTo(block);
37 // Don't close or show Menu.
38 event.stopPropagation();
39 };
40
41 /**
42 *
43 *
44 */
45 this.deleteCodeFile = function(ids) {
46 // Request data.
47 var requestData = {blockId : block.block.get('id'), ids : ids};
48 // Query server / return promise object to caller.
49 return CJTBlocksPage.server.send('codeFiles', 'delete', requestData);
50 };
51
52 /**
53 *
54 *
55 *
56 */
57 this.getList = function() {
58 // Request data.
59 var requestData = {blockId :block.block.get('id')};
60 // Query server / return promise object to caller.
61 return CJTBlocksPage.server.send('codeFiles', 'getList', requestData);
62 };
63
64 this.ondeleteblock = function() {
65 // Don't delete MENU if it being appended under current block.
66 if (CJTBlockCodeFileView.block === block) {
67 CJTBlockCodeFileView.deattach();
68 }
69 };
70 /**
71 *
72 *
73 *
74 */
75 this.save = function(data) {
76 // Buold request params.
77 var requestData = {blockId : block.block.get('id'), codeFile : data};
78 // Send request.
79 return CJTBlocksPage.server.send('codeFiles', 'save', requestData, 'post');
80 };
81
82 /**
83 *
84 *
85 *
86 */
87 this.switchFile = function(codeFile) {
88 // INitialize.
89 var model = block.block;
90 var blockId = model.get('id');
91 // Request data.
92 var requestData = {blockId : blockId, codeFileId : codeFile.id};
93 var promise = $.Deferred();
94 // Query server / return promise object to caller.
95 CJTBlocksPage.server.send('codeFiles', 'switch', requestData).done($.proxy(
96 function(rCodeFile) {
97 // Switch Code File.
98 this.file.activeFileId = rCodeFile.id;
99 this.file.name = rCodeFile.name;
100 this.file.type = rCodeFile.type;
101 // Re-Initialize ACE Code Editor.
102 model.aceEditor.getSession().setValue(rCodeFile.code);
103 model.aceEditor.cjtSyncInputField();
104 // Make sure to recalculate changes after force ace editor to be unchanged.
105 var isChanged = CJTBlocksPage.blocks.calculateChanges(block.changes, model.aceEditor.cjtBlockFieldId, false);
106 CJTBlocksPage.blockContentChanged(blockId, isChanged);
107 block.toolbox.buttons.save.enable(isChanged);
108 // Chage Current File Name.
109 this.currentFileName.text(this.file.name);
110 // Reflect View State.
111 promise.resolve(blockId, rCodeFile.id);
112 }, this)
113 );
114 return promise;
115 };
116
117 // Get All input file elements.
118 // sent from server, get the values.
119 // remove them.
120 var fileInputs = block.block.box.find("input[name^='cjtoolbox[" + block.block.get('id') + "][file]']");
121 $.each(fileInputs, $.proxy(
122 function(index, fileInput) {
123 var propertyName = fileInput.name.match(/cjtoolbox\[\d+\]\[file\]\[(\w+)\]/)[1];
124 this.file[propertyName] = fileInput.value;
125 }, this)
126 );
127 // Remove all file inputs sent from server.
128 fileInputs.remove();
129
130 // Switch editor language.
131 block._onswitcheditorlang(undefined, {lang : this.file.type ? this.file.type : block.block.get('editorLang', 'css')});
132 /// Load block file related features ///
133 // File name and files list.
134 this.currentFileName = $('<a>').addClass('file').text(this.file.name)
135 .insertAfter(block.elements.blockName)
136 .before($('<span class="name-file-separator">|</span>'))
137 .click($.proxy(_onclickfilename, this));
138 };
139
140 })(jQuery);