DropBox, GDrive and GitHub modules now look the same

This commit is contained in:
coderaiser 2012-12-21 08:41:49 -05:00
parent 7e7095a642
commit 530f2b5146
7 changed files with 101 additions and 103 deletions

View file

@ -32,6 +32,9 @@ inside event function varible called event do not exist
changed redirecting url to /auth and added rout function
to cloudcmd.js
* DropBox, GDrive and GitHub modules now look the same.
2012.12.12, Version 0.1.8
* Added ability to shutdown Cloud Commander

View file

@ -1067,6 +1067,26 @@ var CloudCommander, Util, DOM, CloudFunc;
return DOM.addClass(pElement, 'hidden');
};
/**
* open window with URL
* @param pUrl
*/
DOM.openWindow = function(pUrl){
var left = 140,
top = 187,
width = 1000,
height = 650,
lOptions = 'left=' + left +
',top=' + top +
',width=' + width +
',height=' + height +
',personalbar=0,toolbar=0' +
',scrollbars=1,resizable=1';
window.open(pUrl, 'Cloud Commander Auth', lOptions);
};
/**
* remove child of element
* @param pChild

View file

@ -61,14 +61,13 @@ var CloudCommander, Util, DOM, $;
lObj.callback = function(key, opt){
getCurrentData(function(pParams){
var lObject = cloudcmd[pObjectName],
lName = pParams.name,
lData = pParams.data;
var lObject = cloudcmd[pObjectName];
if('init' in lObject)
lObject.uploadFile(lData, lName);
lObject.uploadFile(pParams);
else
Util.exec(lObject, function(){
cloudcmd[pObjectName].uploadFile(lData, lName);
cloudcmd[pObjectName].uploadFile(pParams);
});
});
@ -119,25 +118,9 @@ var CloudCommander, Util, DOM, $;
upload: {
name: 'Upload to',
items: {
'GitHub': getUploadToItem('GitHub'),
'gdrive': {
name: 'GDrive',
callback: function(key, opt){
getCurrentData(function(pParams){
var lGDrive = cloudcmd.GDrive;
if('init' in lGDrive)
lGDrive.init(pParams);
else
Util.exec(cloudcmd.GDrive, pParams);
});
Util.log('Uploading to gdrive...');
}
},
'DropBox': getUploadToItem('DropBox')
'GitHub' : getUploadToItem('GitHub'),
'GDrive' : getUploadToItem('GDrive'),
'DropBox' : getUploadToItem('DropBox')
}
},

View file

@ -4,7 +4,7 @@ var CloudCommander, Util, DOM, CloudFunc, Dropbox, cb, Client;
(function(){
"use strict";
var cloudcmd = CloudCommander,
var CloudCmd = CloudCommander,
//Client,
DropBoxStore = {};
@ -19,9 +19,10 @@ var CloudCommander, Util, DOM, CloudFunc, Dropbox, cb, Client;
function load(pCallBack){
console.time('dropbox load');
var lSrc = '//cdnjs.cloudflare.com/ajax/libs/dropbox.js/0.7.1/dropbox.min.js',
lLocal = CloudFunc.LIBDIRCLIENT + 'storage/dropbox/lib/dropbox.min.js',
lOnload = function(){
//var lSrc = '//cdnjs.cloudflare.com/ajax/libs/dropbox.js/0.7.1/dropbox.min.js',
var lSrc = CloudCmd.LIBDIRCLIENT + 'storage/dropbox/lib/dropbox.js',
lLocal = CloudCmd.LIBDIRCLIENT + 'storage/dropbox/lib/dropbox.min.js',
lOnload = function(){
console.timeEnd('dropbox load');
DOM.Images.hideLoad();
@ -54,7 +55,7 @@ var CloudCommander, Util, DOM, CloudFunc, Dropbox, cb, Client;
* @param pData = {key, secret}
*/
DropBoxStore.login = function(pCallBack){
cloudcmd.getConfig(function(pConfig){
CloudCmd.getConfig(function(pConfig){
Client = new Dropbox.Client({
key: pConfig.dropbox_encoded_key
});
@ -72,19 +73,23 @@ var CloudCommander, Util, DOM, CloudFunc, Dropbox, cb, Client;
/**
* upload file to DropBox
*/
DropBoxStore.uploadFile = function(pContent, pFileName){
if(pContent){
DropBoxStore.uploadFile = function(pParams, pCallBack){
var lContent = pParams.data,
lName = pParams.name;
if(lContent){
DOM.Images.showLoad();
if(!pFileName)
pFileName = Util.getDate();
if(!lName)
lName = Util.getDate();
Client.writeFile(pFileName, pContent, function(pError, pData){
Client.writeFile(lName, lContent, function(pError, pData){
DOM.Images.hideLoad();
console.log(pError || pData);
Util.exec(pCallBack);
});
}
return pContent;
return lContent;
};
DropBoxStore.init = function(pCallBack){
@ -95,8 +100,8 @@ var CloudCommander, Util, DOM, CloudFunc, Dropbox, cb, Client;
load
]);
cloudcmd.DropBox.init = null;
CloudCmd.DropBox.init = null;
};
cloudcmd.DropBox = DropBoxStore;
CloudCmd.DropBox = DropBoxStore;
})();

View file

@ -7,42 +7,37 @@ var CloudCommander, Util, DOM, gapi;
GDrive = {};
function authorize(pData){
/* https://developers.google.com/drive/credentials */
var lCLIENT_ID = '255175681917.apps.googleusercontent.com',
lSCOPES = 'https://www.googleapis.com/auth/drive',
lParams = {
'client_id' : lCLIENT_ID,
'scope' : lSCOPES,
'immediate' : false
};
setTimeout(function() {
gapi.auth.authorize(lParams, function(pAuthResult){
if (pAuthResult && !pAuthResult.error)
uploadFile(pData);
});
}, 500);
}
/* PRIVATE FUNCTIONS */
function load(pData){
/**
* load google api library
*/
function load(pCallBack){
var lUrl = 'https://apis.google.com/js/client.js';
DOM.jsload(lUrl, function(){
authorize(pData);
/* https://developers.google.com/drive/credentials */
var lCLIENT_ID = '255175681917.apps.googleusercontent.com',
lSCOPES = 'https://www.googleapis.com/auth/drive',
lParams = {
'client_id' : lCLIENT_ID,
'scope' : lSCOPES,
'immediate' : false
};
setTimeout(function() {
gapi.auth.authorize(lParams, function(pAuthResult){
if (pAuthResult && !pAuthResult.error)
gapi.client.load('drive', 'v2', function() {
Util.exec(pCallBack);
});
});
}, 500);
});
}
/**
* Start the file upload.
*
* @param {Object} evt Arguments from the file selector.
*/
function uploadFile(pData) {
gapi.client.load('drive', 'v2', function() {
GDrive.uploadFile(pData);
});
}
/**
* Insert new file.
@ -50,20 +45,20 @@ var CloudCommander, Util, DOM, gapi;
* @param {File} fileData {name, data} File object to read data from.
* @param {Function} callback Function to call when the request is complete.
*/
GDrive.uploadFile = function(pData, callback) {
var lData = pData.data,
lName = pData.name,
GDrive.uploadFile = function(pParams, pCallBack) {
var lContent = pParams.data,
lName = pParams.name,
boundary = '-------314159265358979323846',
delimiter = "\r\n--" + boundary + "\r\n",
close_delim = "\r\n--" + boundary + "--",
contentType = pData.type || 'application/octet-stream',
contentType = pParams.type || 'application/octet-stream',
metadata = {
'title' : lName,
'mimeType' : contentType
},
base64Data = btoa(lData),
base64Data = btoa(lContent),
multipartRequestBody =
delimiter +
@ -87,17 +82,20 @@ var CloudCommander, Util, DOM, gapi;
'body': multipartRequestBody
});
if (!callback)
callback = function(file) {
if (!pCallBack)
pCallBack = function(file) {
console.log(file);
};
request.execute(callback);
request.execute(pCallBack);
};
GDrive.init = function(pData){
load(pData);
GDrive.init = function(pCallBack){
Util.loadOnLoad([
Util.retExec(pCallBack),
load
]);
};
cloudcmd.GDrive = GDrive;

View file

@ -84,21 +84,8 @@ var CloudCommander, Util, DOM, $, Github, cb;
DOM.ajax(lData);
}
else{
var lUrl = '//' + window.location.host + '/auth/github',
left = 140,
top = 187,
width = 1000,
height = 650,
lOptions = 'left=' + left +
',top=' + top +
',width=' + width +
',height=' + height +
',personalbar=0,toolbar=0' +
',scrollbars=1,resizable=1';
window.open(lUrl, 'Cloud Commander Auth', lOptions);
var lUrl = '//' + window.location.host + '/auth/github';
DOM.openWindow(lUrl);
}
}
};
@ -142,11 +129,14 @@ var CloudCommander, Util, DOM, $, Github, cb;
/**
* function creates gist
*/
cloudcmd.GitHub.uploadFile = function(pContent, pFileName){
if(pContent){
cloudcmd.GitHub.uploadFile = function(pParams, pCallBack){
var lContent = pParams.data,
lName = pParams.name;
if(lContent){
DOM.Images.showLoad();
if(!pFileName)
pFileName = Util.getDate();
if(!lName)
lName = Util.getDate();
var lGist = GithubLocal.getGist(),
lFiles = {},
@ -157,8 +147,8 @@ var CloudCommander, Util, DOM, $, Github, cb;
public: true
};
lFiles[pFileName] ={
content: pContent
lFiles[lName] ={
content: lContent
};
lOptions.files = lFiles;
@ -167,10 +157,12 @@ var CloudCommander, Util, DOM, $, Github, cb;
DOM.Images.hideLoad();
console.log(pError || pData);
console.log(pData && pData.html_url);
Util.exec(pCallBack);
});
}
return pContent;
return lContent;
};
cloudcmd.GitHub.init = function(pCallBack){

File diff suppressed because one or more lines are too long