diff --git a/ChangeLog b/ChangeLog index fdac7986..9a799c12 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ * Changed the way of getting github application id (now it's just from config, rest api removed). +* Added ability to upload files to GDrive. 2012.12.12, Version 0.1.8 diff --git a/lib/client.js b/lib/client.js index ae3e3767..d2632079 100644 --- a/lib/client.js +++ b/lib/client.js @@ -362,6 +362,7 @@ function initModules(pCallBack){ lNames = {}; lNames[lStorage + '_dropbox'] = 'DropBox', lNames[lStorage + '_github' ] = 'GitHub', + lNames[lStorage + '_gdrive' ] = 'GDrive', lDisableMenuFunc(); diff --git a/lib/client/menu.js b/lib/client/menu.js index 6babe02e..92db3f1f 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -49,23 +49,32 @@ var CloudCommander, Util, DOM, CloudFunc, $; // define the elements of the menu items: { - view: {name: 'View', callback: function(key, opt){ - showEditor(true); - }}, + view: { + name : 'View', + callback : function(key, opt){ + showEditor(true); + } + }, - edit: {name: 'Edit', callback: function(key, opt){ - showEditor(); - }}, + edit: { + name : 'Edit', + callback : function(key, opt){ + showEditor(); + } + }, - delete: {name: 'Delete', + delete: { + name: 'Delete', callback: function(key, opt){ DOM.promptRemoveCurrent(); - }}, + } + }, upload: { - name: "Upload to", + name: 'Upload to', items: { - 'upload_to_gist': {name: 'Gist', + 'gist': { + name: 'Gist', callback: function(key, opt){ var lCurrent = DOM.getCurrentFile(), lPath = DOM.getCurrentPath(), @@ -93,42 +102,81 @@ var CloudCommander, Util, DOM, CloudFunc, $; Util.log('Uploading to gist...'); } }, - }, - }, - download: {name: 'Download',callback: function(key, opt){ - DOM.Images.showLoad(); - - var lCurrent = DOM.getCurrentFile(), - lLink = DOM.getByTag('a', lCurrent)[0].href; - - console.log('downloading file ' + lLink +'...'); - - lLink = lLink + '?download'; - - lLink = Util.removeStr( lLink, CloudFunc.NOJS ); - var lId = DOM.getIdBySrc(lLink); - - if(!DOM.getById(lId)){ - var lDownload = DOM.anyload({ - name : 'iframe', - async : false, - className : 'hidden', - src : lLink, - func : function(){ - DOM.Images.hideLoad(); - } - }); - DOM.Images.hideLoad(); - setTimeout(function() { - document.body.removeChild(lDownload); - }, 10000); + 'gdrive': { + name: 'GDrive', + + callback: function(key, opt){ + + + var lCurrent = DOM.getCurrentFile(), + lPath = DOM.getCurrentPath(), + lName = DOM.getCurrentName(lCurrent); + + DOM.ajax({ + url : lPath, + error : DOM.Images.showError, + success : function(data, textStatus, jqXHR){ + if( Util.isObject(data) ) + data = JSON.stringify(data, null, 4); + var lData = { + data: data, + name: lName + }; + + var lGDrive = cloudcmd.GDrive; + + if('init' in lGDrive) + lGDrive.init(lData); + else + Util.exec(cloudcmd.GDrive, lData); + } + }); + + Util.log('Uploading to gdrive...'); + } + } + } + }, + + + download: { + name: 'Download', + callback: function(key, opt){ + DOM.Images.showLoad(); + + var lCurrent = DOM.getCurrentFile(), + lLink = DOM.getByTag('a', lCurrent)[0].href; + + console.log('downloading file ' + lLink +'...'); + + lLink = lLink + '?download'; + + lLink = Util.removeStr( lLink, CloudFunc.NOJS ); + var lId = DOM.getIdBySrc(lLink); + + if(!DOM.getById(lId)){ + var lDownload = DOM.anyload({ + name : 'iframe', + async : false, + className : 'hidden', + src : lLink, + func : function(){ + DOM.Images.hideLoad(); + } + }); + + DOM.Images.hideLoad(); + setTimeout(function() { + document.body.removeChild(lDownload); + }, 10000); + } + else + DOM.Images.showError({ + responseText: 'Error: You trying to' + + 'download same file to often'}); } - else - DOM.Images.showError({ - responseText: 'Error: You trying to' + - 'download same file to often'}); - }} + } } }; } diff --git a/lib/client/storage/_github.js b/lib/client/storage/_github.js index 0f582e6b..18f48277 100644 --- a/lib/client/storage/_github.js +++ b/lib/client/storage/_github.js @@ -9,7 +9,6 @@ var CloudCommander, Util, DOM, $, Github, cb; APIURL = '/api/v1', AuthURL = APIURL + '/auth', - GitHubIdURL = APIURL + '/github_key', GitHub_ID, GithubLocal, @@ -103,7 +102,7 @@ var CloudCommander, Util, DOM, $, Github, cb; Util.exec(pCallBack); } - /* PUBLICK FUNCTIONS */ + /* PUBLIC FUNCTIONS */ GithubStore.basicLogin = function(pUser, pPasswd){ GithubLocal = new Github({ username: pUser, diff --git a/lib/util.js b/lib/util.js index 5c7ec2ca..498c1a27 100644 --- a/lib/util.js +++ b/lib/util.js @@ -290,6 +290,32 @@ var Util, exports; return lRet; }; + /** + * set timout before callback would be called + * @param pArgs {func, callback, time} + */ + Util.setTimeout = function(pArgs){ + var lDone, + lFunc = pArgs.func, + lTime = pArgs.time || 1000, + lCallBack = function(pArgument){ + if(!lDone){ + lDone = Util.exec(pArgs.callback, pArgument); + } + }; + + var lTimeoutFunc = function(){ + setTimeout(function(){ + Util.exec(lFunc, lCallBack); + if(!lDone) + lTimeoutFunc(); + }, lTime); + }; + + lTimeoutFunc(); + }; + + /** * function execute param function in * try...catch block diff --git a/modules.json b/modules.json index 46d42f3a..02aad66f 100644 --- a/modules.json +++ b/modules.json @@ -4,5 +4,6 @@ "viewer", "storage/_github", "storage/_dropbox", + "storage/_gdrive", "terminal" ] \ No newline at end of file