Changeset 16 for pro-bachkim-filespace/sourcecode/assets/js/vsgrid.js
- Timestamp:
- Jun 26, 2014 5:37:23 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pro-bachkim-filespace/sourcecode/assets/js/vsgrid.js
r15 r16 8 8 if( o.directoryTreeData == undefined ) o.directoryTreeData = null; 9 9 if( o.dirIDprefix == undefined ) o.dirIDprefix = null; 10 if( o.host == undefined ) o.host = 'http://localhost/'; 11 12 if( o.sharemodal == undefined ) o.sharemodal = $("#box-shareto"); 13 if( o.copymodal == undefined ) o.copymodal = $("#box-copyto"); 14 if( o.movemodal == undefined ) o.movemodal = $("#box-moveto"); 15 16 var currentObj = {}; 10 17 11 18 var createNode = function (d) { … … 33 40 $(o.container).append(strHTML); 34 41 35 $('div[rel="id:'+ d.id +'"]').bind('click',function(e){itemClick(this)}); 42 $('div[rel="id:'+ d.id +'"]').bind('click',function(e){itemClick(this)}); 43 36 44 $('div[rel="id:'+ d.id +'"]').contextMenu({ 37 45 menu: 'gridMenu', 38 46 disabledItems: disabledItemsList 39 47 }, function(action, el, pos) { 40 48 itemClick(el); 41 49 switch(action) { 42 50 case 'rename': 43 itemClick(el);44 51 rename(el); 52 break; 53 case 'share': 54 showShareModal(currentObj); 55 break; 56 case 'copy': 57 showCopyModal(); 58 break; 59 case 'cut': 60 showMoveModal(); 45 61 break; 46 62 default: … … 52 68 53 69 var keyboardRename = function () { 54 $(document). keypress(function(e) {70 $(document).bind('keydown','keypress', function(e) { 55 71 var selectedItem = $('.selector.selected').parent(); 72 56 73 switch( e.keyCode ) { 57 74 case 113: 58 75 rename(selectedItem); 59 76 break; 60 case 32:77 case 27: 61 78 cancelRename(selectedItem); 62 79 break; … … 64 81 break; 65 82 } 66 return false; 67 }); 83 }); 84 } 85 86 var showShareModal = function (obj) { 87 if (obj.type == undefined || obj.type == null) obj.type = 'directory'; 88 $(o.sharemodal).modal('show'); 89 $(o.sharemodal).find('INPUT#txtSelectedObj').val(obj.name); 90 $(o.sharemodal).find('.modal-header').text('Chia sẻ ' + (obj.type == 'directory'?'thư mục':'file') + ' [' + obj.name + ']'); 91 } 92 93 var showCopyModal = function () { 94 $(o.copymodal).modal('show'); 95 /*$(o.copymodal).find('INPUT#txtSelectedObj').val(currentObj.name); 96 $(o.copymodal).find('.modal-header').text('Chia sẻ ' + (currentObj.type == 'directory'?'thư mục':'file') + ' [' + currentObj.name + ']');*/ 97 } 98 99 var showMoveModal = function () { 100 $(o.movemodal).modal('show'); 68 101 } 69 102 … … 78 111 $(i).find('.selector').removeClass('unselected'); 79 112 $(i).find('.selector').addClass('selected'); 113 114 if ($(i).find('.file-name').text() != '') 115 currentObj.name = $(i).find('.file-name').text(); 116 117 currentObj.id = $(i).attr('rel').substring(3); 118 currentObj.type = $(i).find('>div>div').hasClass('icon-directory') ? 'directory':'file'; 119 console.log(currentObj.type); 80 120 } 81 121 … … 95 135 }); 96 136 } 97 137 98 138 for (var i = 0 ; i < childFile.length; i++) { 99 139 if (childFile[i].parentID != curentDirID) continue; … … 105 145 }); 106 146 } 147 148 keyboardRename(); 107 149 } 108 150 109 151 var rename = function (e) { 110 152 var nameObj = $(e).find('.file-name'); 111 var oldName = $(nameObj).text();112 153 var editor = document.createElement ('INPUT'); 113 154 editor.type = 'text'; 114 155 editor.className = 'rename'; 115 editor.value = oldName;116 156 117 157 $(nameObj).text(''); 118 158 $(nameObj).append(editor); 159 160 $(editor).attr('value', currentObj.name); 119 161 editor.focus(); 120 162 $(editor).select(); 163 $(editor).bind('focusout',function (e) { 164 cancelRename($(this).parent().parent()); 165 }); 166 167 $(editor).bind('keypress',function (e) { 168 var keycode = (e.keyCode ? e.keyCode : e.which); 169 if(keycode == '13'){ 170 completeRename($(this).parent()); 171 } 172 else { 173 174 } 175 e.stopPropagation(); 176 }); 121 177 } 122 178 123 179 var cancelRename = function (e) { 124 var oldName = $(e).find('INPUT.rename').attr('value');125 180 $(e).find('INPUT.rename').remove(); 126 $(e).find('.file-name').text(oldName); 127 181 $(e).find('.file-name').text(currentObj.name); 182 } 183 184 var completeRename = function (e) { 185 186 var postdata = {id:currentObj.id, 187 objtype:currentObj.type, 188 newname:$(e).find('INPUT.rename').val()} 189 sendCommand({ 190 script:'ajax/privatecontent/rename', 191 postdata:postdata, 192 callbackSuccess: function (parsedData) { 193 if (parsedData.RESULT == true) { 194 currentObj.name = parsedData.UPDATED.name; 195 $(e).find('INPUT.rename').remove(); 196 $(e).text(currentObj.name); 197 }else return false; 198 } 199 }); 200 } 201 202 var sendCommand = function (p) { 203 if( p.postdata == undefined ) p.postdata = null; 204 if( p.script == undefined ) p.script = o.script; 205 if( p.callbackSuccess == undefined ) p.callbackSuccess = null; 206 if( p.callbackDone == undefined ) p.callbackDone = null; 207 if( p.callbackFail == undefined ) p.callbackFail = null; 208 if( p.callbackAlways == undefined ) p.callbackAlways = null; 209 210 if (p.script != null) { 211 $.post(o.host + p.script, p.postdata, function (data){ 212 if (data) { 213 parseData = $.parseJSON(data); 214 } 215 216 if (p.callbackSuccess != null) { 217 p.callbackSuccess(parseData); 218 } 219 220 }).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);}); 221 } 128 222 } 129 223 … … 133 227 o.dirIDprefix = data.dirIDprefix 134 228 renderGrid(o); 135 keyboardRename(); 229 } 230 231 this.showModal = function (act, obj) { 232 switch( act ) { 233 case 'copy': 234 break; 235 case 'move': 236 break; 237 case 'share': 238 showShareModal(obj); 239 break; 240 default: 241 break; 242 } 136 243 } 137 244
Note: See TracChangeset
for help on using the changeset viewer.