Ignore:
Timestamp:
Jun 26, 2014 5:37:23 PM (11 years ago)
Author:
dungnv
Message:
 
Location:
pro-bachkim-filespace/sourcecode/assets/js
Files:
3 added
2 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
  • pro-bachkim-filespace/sourcecode/assets/js/vstree.js

    r15 r16  
    1919                        if( o.grid == undefined ) o.grid = null;
    2020                       
     21                        var currentObj = {};
     22                       
    2123                        // PRIVATE methods
    2224                        var sendCommand = function (p) {
     
    4749
    4850                        var renderTree = function  (parseData) {
    49 
    5051                                o.directoryTreeData = parseData;                               
    5152                                var directoryData = parseData.DIRECTORIES;
     
    8081                                if( d.addToJSONData == undefined ) d.addToJSONData = false;
    8182                               
     83                                var disabledItemsList = null;
     84                                if (d.name == o.homeDirNameDisplay)
     85                                        disabledItemsList = ['cut','delete'];
     86                               
    8287                                if (d.curentNode != null) {
    8388                                        var strHTML = '<ul class="vstree"><li id="' + o.dirIDprefix + d.id + '" class="directory collapsed"><a href="#" rel="' + d.name + '">' + d.name + '</a></li></ul>';
     
    107112                               
    108113                                $('#' + o.dirIDprefix + d.id).find('a').contextMenu({
    109                                         menu: 'treeMenu'
     114                                        menu: 'treeMenu',
     115                                        disabledItems: disabledItemsList
    110116                                }, function(action, el, pos) {
    111                                         alert(
    112                                                 'Action: ' + action + '\n\n' +
    113                                                 'Element text: ' + $(el).text() + '\n\n' +
    114                                                 'X: ' + pos.x + '  Y: ' + pos.y + ' (relative to element)\n\n' +
    115                                                 'X: ' + pos.docX + '  Y: ' + pos.docY+ ' (relative to document)'
    116                                                 );
     117                                        selectDir(el);
     118                                        switch(action) {
     119                                                case 'rename':
     120                                                        rename(el);
     121                                                        break;
     122                                                case 'share':
     123                                                        o.grid.showModal(action, currentObj);
     124                                                        break;
     125                                                default:
     126                                                        break;
     127                                        }
    117128                                });
    118129                               
     
    154165                                $('.currentDir').removeClass('currentDir');
    155166                                $(c).addClass('currentDir');
     167                               
     168                                var cid = $(c).parent().attr('id');
     169                                var pid = cid.substring(o.dirIDprefix.length, cid.length);
     170                               
     171                                currentObj.id = pid;
     172                                currentObj.name = $(c).attr('rel');
     173                               
     174                                keyboardRename ();
     175                               
    156176                                sendtoGrid();
    157177                        }
     
    165185                        }
    166186
     187                        var rename = function (o) {
     188                                var editor = document.createElement ('INPUT');
     189                                editor.type = 'text';
     190                                editor.className = 'rename';
     191                               
     192                                $(o).text('');
     193                                $(o).append(editor);
     194                               
     195                                $(editor).attr('value', currentObj.name); 
     196                                editor.focus();
     197                                $(editor).select();
     198                               
     199                                $(editor).bind('focusout',function (e) {
     200                                        cancelRename($(o));
     201                                });
     202                               
     203                                $(editor).bind('keypress',function (e) {
     204                                var keycode = (e.keyCode ? e.keyCode : e.which);
     205                                if(keycode == '13'){
     206                                        completeRename($(o));
     207                                }
     208                                else {
     209                                       
     210                                }
     211                                e.stopPropagation();
     212                                });
     213                        }
     214                       
     215                        var cancelRename = function (o) {
     216                                $(o).find('>INPUT').remove();
     217                                $(o).text(currentObj.name);
     218                        }
     219                       
     220                        var completeRename = function (o) {
     221                                var postdata = {id:currentObj.id,
     222                                                objtype:'directory',
     223                                                newname:$(o).find('INPUT.rename').val()}
     224                               
     225                                sendCommand({
     226                                        script:'ajax/privatecontent/rename',
     227                                        postdata:postdata,
     228                                        callbackSuccess: function (parsedData) {
     229                                                if (parsedData.RESULT == true) {
     230                                                        currentObj.name = parsedData.UPDATED.name;
     231                                                        $(o).find('INPUT.rename').remove();
     232                                                        $(o).text(currentObj.name);
     233                                                }else return false;
     234                                        }
     235                                });
     236                        }
     237                       
     238                        var keyboardRename = function () {
     239                                $(document).bind('keydown','keypress', function(e) {
     240                                        var selectedItem = $('.currentDir');
     241                                       
     242                                        switch( e.keyCode ) {
     243                                                case 113:
     244                                                        rename(selectedItem);
     245                                                        break;
     246                                                case 27:
     247                                                        cancelRename(selectedItem);
     248                                                        break;
     249                                                default:
     250                                                        break;
     251                                        }
     252                                });
     253                        }
     254                       
    167255                        loadTree();
    168256                        // END - PRIVATE methods
Note: See TracChangeset for help on using the changeset viewer.