Ignore:
Timestamp:
May 27, 2014 7:27:44 PM (11 years ago)
Author:
dungnv
Message:
 
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  
    5151                var privateTree =  $('#treeview-container').violetTree({
    5252                        script:'getdata.php',
    53                         dataSource: 'AJAX',
    5453                        expandEasing: 'easeOutBounce',
    5554                        collapseEasing: 'easeOutBounce',
     
    6867                });
    6968
     69                $('#btnCopy').click (function(){
     70                        privateTree.copy();
     71                });
     72
    7073                /**
    7174                END - For Directory Tree
  • pro-bachkim-filespace/violetspace-prototype/assets/js/vsfilemanager.js

    r4 r5  
    77                        if( o.homeDirNameDisplay == undefined ) o.homeDirNameDisplay = 'Home';
    88                        if( o.script == undefined ) o.script = null;
    9                         if( o.dataSource == undefined ) o.dataSource = 'AJAX'; //'LOADED'
    10                         if( o.data == undefined ) o.data = null;
    119                        if( o.container == undefined ) o.container = $(this);
    1210                        if( o.dirIDprefix == undefined ) o.dirIDprefix = 'vsdir_';
     
    1816
    1917                        // 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
    2039                        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) {
    3444                                var homeNode = createNode({
    3545                                        id:0,
     
    3848
    3949                                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++) {
    4352                                                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 : false
     53                                                        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
    4857                                                })
    4958                                        };
     
    8796                        //END - Create a node of Tree
    8897
    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();
    92102                        }
    93103
     
    139149
    140150                        this.createDir = function(c) {
    141 
    142151                                var cid = $(c).parent().attr('id');
    143152                                var pid = cid.substring(o.dirIDprefix.length, cid.length);
     
    145154                                var dirName = prompt("Please enter new directory name", "");
    146155
    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                                                                        }
    158164                                });
    159165                        }
     
    164170                                var confirmChild = true;
    165171
     172                                var cid = $(c).parent().attr('id');
     173                                var pid = cid.substring(o.dirIDprefix.length, cid.length);
     174
    166175                                if (isHome(c)) return;
    167176
     
    171180                                        confirmChild = confirm('This node has childs, you still want to delete it?');
    172181
    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');
    175197                        }
    176198
     
    181203                        return this.initialize();
    182204                },
     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                }
    183213        });
    184214
Note: See TracChangeset for help on using the changeset viewer.