Changeset 5 for pro-bachkim-filespace/violetspace-prototype/assets/js
- Timestamp:
- May 27, 2014 7:27:44 PM (11 years ago)
- Location:
- pro-bachkim-filespace/violetspace-prototype/assets/js
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pro-bachkim-filespace/violetspace-prototype/assets/js/filemanager/filemanager.js
r4 r5 51 51 var privateTree = $('#treeview-container').violetTree({ 52 52 script:'getdata.php', 53 dataSource: 'AJAX',54 53 expandEasing: 'easeOutBounce', 55 54 collapseEasing: 'easeOutBounce', … … 68 67 }); 69 68 69 $('#btnCopy').click (function(){ 70 privateTree.copy(); 71 }); 72 70 73 /** 71 74 END - For Directory Tree -
pro-bachkim-filespace/violetspace-prototype/assets/js/vsfilemanager.js
r4 r5 7 7 if( o.homeDirNameDisplay == undefined ) o.homeDirNameDisplay = 'Home'; 8 8 if( o.script == undefined ) o.script = null; 9 if( o.dataSource == undefined ) o.dataSource = 'AJAX'; //'LOADED'10 if( o.data == undefined ) o.data = null;11 9 if( o.container == undefined ) o.container = $(this); 12 10 if( o.dirIDprefix == undefined ) o.dirIDprefix = 'vsdir_'; … … 18 16 19 17 // PRIVATE methods 18 var sendCommand = function (p) { 19 if( p.postdata == undefined ) p.postdata = null; 20 if( p.callbackSuccess == undefined ) p.callbackSuccess = null; 21 if( p.callbackDone == undefined ) p.callbackDone = null; 22 if( p.callbackFail == undefined ) p.callbackFail = null; 23 if( p.callbackAlways == undefined ) p.callbackAlways = null; 24 25 if (o.script != null) { 26 $.post(o.script, p.postdata, function (data){ 27 if (data) { 28 parseData = $.parseJSON(data); 29 } 30 31 if (p.callbackSuccess != null) { 32 p.callbackSuccess(parseData); 33 } 34 35 }).done(function() {if (p.callbackDone != null)p.callbackDone(this);}).fail(function() {if (p.callbackFail != null)p.callbackFail(this);}).always(function() {if (p.callbackAlways != null)p.callbackAlways(this);}); 36 } 37 } 38 20 39 var loadTree = function () { 21 if (o.dataSource == 'AJAX') { 22 $.post(o.script, 23 function(data){ 24 if (!data) return; 25 var parsedData = $.parseJSON(data); 26 o.data = parsedData; 27 renderTree (); 28 } 29 ).done(function() {}).fail(function() {}).always(function() {}); 30 } 31 }; 32 33 var renderTree = function () { 40 sendCommand ({postdata:null,callbackSuccess:renderTree}); 41 }; 42 43 var renderTree = function (parseData) { 34 44 var homeNode = createNode({ 35 45 id:0, … … 38 48 39 49 selectDir($(homeNode).find('> A')); 40 41 if (o.data != null) { 42 for (var i = 0; i < o.data.length ; i++) { 50 if (parseData != null) { 51 for (var i = 0; i < parseData.length ; i++) { 43 52 var node = createNode ({ 44 id: o.data[i].id,45 name: o.data[i].name,46 curentNode: $('#' + o.dirIDprefix + o.data[i].parentID).find('> A'),47 hidden: ( o.data[i].parentID > 0) ? true : false53 id: parseData[i].id, 54 name: parseData[i].name, 55 curentNode: $('#' + o.dirIDprefix + parseData[i].parentID).find('> A'), 56 hidden: (parseData[i].parentID > 0) ? true : false 48 57 }) 49 58 }; … … 87 96 //END - Create a node of Tree 88 97 89 var deleteNode = function (n) { 90 if (!$(n).parent().hasClass('home')) 91 $(n).remove(); 98 var deleteNode = function (parsedData) { 99 if (parsedData.isSuccess == false) return false; 100 if (!$('#' + o.dirIDprefix + parsedData.id).hasClass('home')) 101 $('#' + o.dirIDprefix + parsedData.id).parent().remove(); 92 102 } 93 103 … … 139 149 140 150 this.createDir = function(c) { 141 142 151 var cid = $(c).parent().attr('id'); 143 152 var pid = cid.substring(o.dirIDprefix.length, cid.length); … … 145 154 var dirName = prompt("Please enter new directory name", ""); 146 155 147 $.post(o.script,{action:"create_dir",parentID:pid,name:dirName}, function (data) { 148 if (!data) return; 149 var parsedData = $.parseJSON(data); 150 151 createNode({ 152 id: parsedData.id, 153 name: parsedData.name, 154 curentNode: c, 155 hidden: false, 156 //customEvent: {eventName: "click", eventTrigger: function(o){alert('This click!')}} 157 }); 156 sendCommand({ 157 postdata:{action:"create_dir",parentID:pid,name:dirName}, 158 callbackSuccess: function (parsedData) {createNode({ 159 id: parsedData.id, 160 name: parsedData.name, 161 curentNode: c, 162 hidden: false,}); 163 } 158 164 }); 159 165 } … … 164 170 var confirmChild = true; 165 171 172 var cid = $(c).parent().attr('id'); 173 var pid = cid.substring(o.dirIDprefix.length, cid.length); 174 166 175 if (isHome(c)) return; 167 176 … … 171 180 confirmChild = confirm('This node has childs, you still want to delete it?'); 172 181 173 if (confirmDel && confirmChild) deleteNode(c); 174 182 if (confirmDel && confirmChild) { 183 var postdata = {action:"delete_dir",id:pid} 184 sendCommand({ 185 postdata:postdata, 186 callbackSuccess: function (parsedData) {deleteNode(parsedData)} 187 }); 188 } 189 } 190 191 this.copy = function () { 192 alert ('copy'); 193 } 194 195 this.paste = function () { 196 alert ('paste'); 175 197 } 176 198 … … 181 203 return this.initialize(); 182 204 }, 205 206 violetGrid: function (o) { 207 if( o.container == undefined ) o.container = $(this); 208 if( o.defaultViewMode == undefined ) o.defaultViewMode = 'thumbnail';//or 'list' 209 210 if( o.directoryContent == undefined ) o.directoryContent = null; 211 212 } 183 213 }); 184 214
Note: See TracChangeset
for help on using the changeset viewer.