Ignore:
Timestamp:
Jun 26, 2014 5:37:23 PM (11 years ago)
Author:
dungnv
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pro-bachkim-filespace/sourcecode/assets/js/vsgrid.js

    r15 r16  
    88                        if( o.directoryTreeData == undefined ) o.directoryTreeData = null;
    99                        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 = {};
    1017                       
    1118                        var createNode = function (d) {
     
    3340                                $(o.container).append(strHTML);
    3441
    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                               
    3644                                $('div[rel="id:'+ d.id +'"]').contextMenu({
    3745                                        menu: 'gridMenu',
    3846                                        disabledItems: disabledItemsList
    3947                                }, function(action, el, pos) {
    40                                
     48                                        itemClick(el);
    4149                                        switch(action) {
    4250                                                case 'rename':
    43                                                         itemClick(el);
    4451                                                        rename(el);
     52                                                        break;
     53                                                case 'share':
     54                                                        showShareModal(currentObj);
     55                                                        break;
     56                                                case 'copy':
     57                                                        showCopyModal();
     58                                                        break;
     59                                                case 'cut':
     60                                                        showMoveModal();
    4561                                                        break;
    4662                                                default:
     
    5268                       
    5369                        var keyboardRename = function () {
    54                                 $(document).keypress( function(e) {
     70                                $(document).bind('keydown','keypress', function(e) {
    5571                                        var selectedItem = $('.selector.selected').parent();
     72                                       
    5673                                        switch( e.keyCode ) {
    5774                                                case 113:
    5875                                                        rename(selectedItem);
    5976                                                        break;
    60                                                 case 32:
     77                                                case 27:
    6178                                                        cancelRename(selectedItem);
    6279                                                        break;
     
    6481                                                        break;
    6582                                        }
    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');
    68101                        }
    69102
     
    78111                                $(i).find('.selector').removeClass('unselected');
    79112                                $(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);
    80120                        }
    81121
     
    95135                                        });
    96136                                }
    97 
     137                               
    98138                                for (var i = 0 ; i < childFile.length; i++) {
    99139                                        if (childFile[i].parentID != curentDirID) continue;
     
    105145                                        });
    106146                                }
     147                               
     148                                keyboardRename();
    107149                        }
    108150                       
    109151                        var rename = function (e) {
    110152                                var nameObj = $(e).find('.file-name');
    111                                 var oldName = $(nameObj).text();
    112153                                var editor = document.createElement ('INPUT');
    113154                                editor.type = 'text';
    114155                                editor.className = 'rename';
    115                                 editor.value = oldName;
    116156                               
    117157                                $(nameObj).text('');
    118158                                $(nameObj).append(editor);
     159                               
     160                                $(editor).attr('value', currentObj.name); 
    119161                                editor.focus();
    120162                                $(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                                });
    121177                        }
    122178                       
    123179                        var cancelRename = function (e) {
    124                                 var oldName = $(e).find('INPUT.rename').attr('value');
    125180                                $(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                                }
    128222                        }
    129223
     
    133227                                o.dirIDprefix = data.dirIDprefix
    134228                                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                                }
    136243                        }
    137244
Note: See TracChangeset for help on using the changeset viewer.