From 7b6371fd506f2e7d6ccbfe5f071b9a648ceafc07 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Sun, 3 Mar 2013 14:46:08 -0500 Subject: [PATCH] added filepicker --- ChangeLog | 1 + json/modules.json | 6 + lib/client.js | 7 +- lib/client/menu.js | 4 +- lib/client/storage/_filepicker.js | 38 ++++ lib/client/storage/_github.js | 318 +++++++++++++++--------------- 6 files changed, 209 insertions(+), 165 deletions(-) create mode 100644 lib/client/storage/_filepicker.js diff --git a/ChangeLog b/ChangeLog index 558195b7..eb160aad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ * Added ability create folders. +* Added filepicker. 2012.03.01, Version 0.1.9 diff --git a/json/modules.json b/json/modules.json index 3ea504f4..28b5e6db 100644 --- a/json/modules.json +++ b/json/modules.json @@ -34,6 +34,12 @@ "data": { "id" : "00000000440E696F" } + }, + { + "name": "FilePicker", + "data": { + "key" : "AACq5fTfzRY2E_Rw_4kyaz" + } } ] } diff --git a/lib/client.js b/lib/client.js index 4104d7c7..dbc57c3d 100644 --- a/lib/client.js +++ b/lib/client.js @@ -110,9 +110,10 @@ CloudCmd._loadDir = function(pLink, pNeedRefresh){ * @param pEvent */ CloudCmd._editFileName = function(pParent){ - var lA = DOM.getCurrentLink(pParent); + var lA = DOM.getCurrentLink(pParent), + lName = DOM.getCurrentName(); - if (lA && lA.textContent !== '..'){ + if ( lName !== '..' ){ lA.contentEditable = true; KeyBinding && KeyBinding.unSet(); @@ -413,7 +414,7 @@ CloudCmd._changeLinks = function(pPanelID){ lOnContextMenu_f = function(pEvent){ var lReturn_b = true; - KeyBinding.unSet(); + KeyBinding && KeyBinding.unSet(); /* getting html element * currentTarget - DOM event diff --git a/lib/client/menu.js b/lib/client/menu.js index 4ccf831c..6d8402b6 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -60,9 +60,7 @@ var CloudCommander, Util, DOM, CloudFunc, $; } } else if( Util.isString(pObjectName) ){ - lObj.name = pObjectName; - - lObj.callback = function(key, opt){ + lObj = function(key, opt){ DOM.getCurrentData(function(pParams){ var lObject = CloudCmd[pObjectName]; diff --git a/lib/client/storage/_filepicker.js b/lib/client/storage/_filepicker.js new file mode 100644 index 00000000..bffa3e94 --- /dev/null +++ b/lib/client/storage/_filepicker.js @@ -0,0 +1,38 @@ +var CloudCommander, Util, DOM, $, filepicker; +/* module for work with github */ + +(function(CloudCmd, Util, DOM){ + 'use strict'; + + var FilePicker = function(){ + this.init = function(pCallBack){ + Util.loadOnLoad([ + Util.retExec(pCallBack), + load + ]); + }; + + + this.uploadFile = function(pCallBack){ + filepicker.pick(function(FPFile){ + console.log(FPFile.url); + + Util.exec(pCallBack); + }); + }; + + function load(pCallBack){ + console.time('filepicker load'); + var lHTTP = "https:"===document.location.protocol? "https:" : "http:"; + + DOM.jsload(lHTTP + '//api.filepicker.io/v1/filepicker.js', function(){ + filepicker.setKey('AACq5fTfzRY2E_Rw_4kyaz'); + DOM.Images.hideLoad(); + console.timeEnd('filepicker loaded'); + Util.exec(pCallBack); + }); + } + }; + + CloudCmd.FilePicker = new FilePicker(); +})(CloudCommander, Util, DOM); diff --git a/lib/client/storage/_github.js b/lib/client/storage/_github.js index 552fd481..e1593d2b 100644 --- a/lib/client/storage/_github.js +++ b/lib/client/storage/_github.js @@ -1,159 +1,159 @@ -var CloudCommander, Util, DOM, $, Github, cb; -/* module for work with github */ - -(function(CloudCmd, Util, DOM){ - "use strict"; - - var Cache = DOM.Cache, - GithubLocal, - User, - GitHubStore = {}; - - /* temporary callback function for work with github */ - cb = function (err, data){ Util.log(err || data);}; - - /* PRIVATE FUNCTIONS */ - - /** - * function loads github.js - */ - function load(pCallBack){ - console.time('github load'); - - var lDir = '/lib/client/storage/github/', - lFiles = [ - lDir + 'github.js', - lDir + 'lib/base64.js', - lDir + 'lib/underscore.js' - ]; - - DOM.anyLoadInParallel(lFiles, function(){ - console.timeEnd('github load'); - DOM.Images.hideLoad(); - - Util.exec(pCallBack); - }); - } - - - GitHubStore.autorize = function(pCallBack, pCode){ - var lToken = Cache.get('token'); - if(lToken){ - GitHubStore.Login(lToken); - Util.exec(pCallBack); - } - else{ - var lCode = pCode || window.location.search; - if (lCode || Util.isContainStr(lCode, '?code=') ) - CloudCmd.getConfig(function(pConfig){ - DOM.ajax({ - type : 'put', - url : pConfig && pConfig.api_url + '/auth', - data : Util.removeStr(lCode, '?code='), - success : function(pData){ - if(pData && pData.token){ - lToken = pData.token; - - GitHubStore.Login(lToken); - Cache.set('token', lToken); - Util.exec(pCallBack); - } - else - Util.log('Worning: token not getted...'); - } - }); - }); - else{ - var lUrl = '//' + window.location.host + '/auth/github'; - DOM.openWindow(lUrl); - } - } - }; - - GitHubStore.getUserData = function(pCallBack){ - User.show(null, function(pError, pData){ - if(!pError){ - var lName = pData.name; - Util.log('Hello ' + lName + ' :)!'); - } - else - DOM.Cache.remove('token'); - }); - - Util.exec(pCallBack); - }; - - /* PUBLIC FUNCTIONS */ - GitHubStore.basicLogin = function(pUser, pPasswd){ - GithubLocal = new Github({ - username: pUser, - password: pPasswd, - auth : 'basic' - }); - }; - - GitHubStore.Login = function(pToken){ - Github = GithubLocal = new Github({ - token : pToken, - auth : 'oauth' - }); - - User = GithubLocal.getUser(); - }; - - /** - * function creates gist - */ - GitHubStore.uploadFile = function(pParams, pCallBack){ - var lContent = pParams.data, - lName = pParams.name; - - if(lContent){ - DOM.Images.showLoad(); - if(!lName) - lName = Util.getDate(); - - var lGist = GithubLocal.getGist(), - lFiles = {}, - lHost = CloudCommander.HOST, - lOptions = { - description: 'Uplouded by Cloud Commander from ' + lHost, - public: true - }; - - lFiles[lName] ={ - content: lContent - }; - - lOptions.files = lFiles; - - lGist.create(lOptions, function(pError, pData){ - DOM.Images.hideLoad(); - Util.log(pError || pData); - Util.log(pData && pData.html_url); - - Util.exec(pCallBack); - }); - } - - return lContent; - }; - - GitHubStore.init = function(pCallBack){ - Util.loadOnLoad([ - Util.retExec(pCallBack), - GitHubStore.getUserData, - GitHubStore.autorize, - load - ]); - - GitHubStore.callback = function(){ - Util.loadOnLoad([ - Util.retExec(pCallBack), - GitHubStore.getUserData, - ]); - }; - }; - - CloudCmd.GitHub = GitHubStore; -})(CloudCommander, Util, DOM); +var CloudCommander, Util, DOM, $, Github, cb; +/* module for work with github */ + +(function(CloudCmd, Util, DOM){ + 'use strict'; + + var Cache = DOM.Cache, + GithubLocal, + User, + GitHubStore = {}; + + /* temporary callback function for work with github */ + cb = function (err, data){ Util.log(err || data);}; + + /* PRIVATE FUNCTIONS */ + + /** + * function loads github.js + */ + function load(pCallBack){ + console.time('github load'); + + var lDir = '/lib/client/storage/github/', + lFiles = [ + lDir + 'github.js', + lDir + 'lib/base64.js', + lDir + 'lib/underscore.js' + ]; + + DOM.anyLoadInParallel(lFiles, function(){ + console.timeEnd('github load'); + DOM.Images.hideLoad(); + + Util.exec(pCallBack); + }); + } + + + GitHubStore.autorize = function(pCallBack, pCode){ + var lToken = Cache.get('token'); + if(lToken){ + GitHubStore.Login(lToken); + Util.exec(pCallBack); + } + else{ + var lCode = pCode || window.location.search; + if (lCode || Util.isContainStr(lCode, '?code=') ) + CloudCmd.getConfig(function(pConfig){ + DOM.ajax({ + type : 'put', + url : pConfig && pConfig.api_url + '/auth', + data : Util.removeStr(lCode, '?code='), + success : function(pData){ + if(pData && pData.token){ + lToken = pData.token; + + GitHubStore.Login(lToken); + Cache.set('token', lToken); + Util.exec(pCallBack); + } + else + Util.log('Worning: token not getted...'); + } + }); + }); + else{ + var lUrl = '//' + window.location.host + '/auth/github'; + DOM.openWindow(lUrl); + } + } + }; + + GitHubStore.getUserData = function(pCallBack){ + User.show(null, function(pError, pData){ + if(!pError){ + var lName = pData.name; + Util.log('Hello ' + lName + ' :)!'); + } + else + DOM.Cache.remove('token'); + }); + + Util.exec(pCallBack); + }; + + /* PUBLIC FUNCTIONS */ + GitHubStore.basicLogin = function(pUser, pPasswd){ + GithubLocal = new Github({ + username: pUser, + password: pPasswd, + auth : 'basic' + }); + }; + + GitHubStore.Login = function(pToken){ + Github = GithubLocal = new Github({ + token : pToken, + auth : 'oauth' + }); + + User = GithubLocal.getUser(); + }; + + /** + * function creates gist + */ + GitHubStore.uploadFile = function(pParams, pCallBack){ + var lContent = pParams.data, + lName = pParams.name; + + if(lContent){ + DOM.Images.showLoad(); + if(!lName) + lName = Util.getDate(); + + var lGist = GithubLocal.getGist(), + lFiles = {}, + lHost = CloudCommander.HOST, + lOptions = { + description: 'Uplouded by Cloud Commander from ' + lHost, + public: true + }; + + lFiles[lName] ={ + content: lContent + }; + + lOptions.files = lFiles; + + lGist.create(lOptions, function(pError, pData){ + DOM.Images.hideLoad(); + Util.log(pError || pData); + Util.log(pData && pData.html_url); + + Util.exec(pCallBack); + }); + } + + return lContent; + }; + + GitHubStore.init = function(pCallBack){ + Util.loadOnLoad([ + Util.retExec(pCallBack), + GitHubStore.getUserData, + GitHubStore.autorize, + load + ]); + + GitHubStore.callback = function(){ + Util.loadOnLoad([ + Util.retExec(pCallBack), + GitHubStore.getUserData, + ]); + }; + }; + + CloudCmd.GitHub = GitHubStore; +})(CloudCommander, Util, DOM);