Fixed picker

This commit is contained in:
benweet 2014-05-12 00:17:15 +01:00
parent 47f4d89621
commit bab38a769e
7 changed files with 1041 additions and 985 deletions

View File

@ -27,7 +27,7 @@ define([], function() {
constants.PICASA_PROXY_URL = "https://stackedit-picasa-proxy.herokuapp.com/"; constants.PICASA_PROXY_URL = "https://stackedit-picasa-proxy.herokuapp.com/";
constants.SSH_PROXY_URL = "https://stackedit-ssh-proxy.herokuapp.com/"; constants.SSH_PROXY_URL = "https://stackedit-ssh-proxy.herokuapp.com/";
constants.HTMLTOPDF_URL = "https://stackedit-htmltopdf.herokuapp.com/"; constants.HTMLTOPDF_URL = "https://stackedit-htmltopdf.herokuapp.com/";
constants.TEAM_SERVER_URL = "http://localhost:11583/"; constants.TEAM_SERVER_URL = "/";
// Site dependent // Site dependent
constants.BASE_URL = "http://localhost/"; constants.BASE_URL = "http://localhost/";

View File

@ -14,6 +14,7 @@ define([
var connected = false; var connected = false;
var authorizationMgrMap = {}; var authorizationMgrMap = {};
function AuthorizationMgr(accountId) { function AuthorizationMgr(accountId) {
var permissionList = { var permissionList = {
profile: true profile: true
@ -106,6 +107,7 @@ define([
'https://www.googleapis.com/auth/photos' 'https://www.googleapis.com/auth/photos'
] ]
}; };
function authenticate(task, permission, accountId) { function authenticate(task, permission, accountId) {
var authorizationMgr = authorizationMgrMap[accountId]; var authorizationMgr = authorizationMgrMap[accountId];
if(!authorizationMgr) { if(!authorizationMgr) {
@ -115,6 +117,7 @@ define([
task.onRun(function() { task.onRun(function() {
var currentToken = gapi.auth.getToken(); var currentToken = gapi.auth.getToken();
var newToken; var newToken;
function getTokenInfo() { function getTokenInfo() {
$.ajax({ $.ajax({
url: 'https://www.googleapis.com/oauth2/v1/tokeninfo', url: 'https://www.googleapis.com/oauth2/v1/tokeninfo',
@ -142,8 +145,10 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
var authuser = 0; var authuser = 0;
var immediate; var immediate;
function localAuthenticate() { function localAuthenticate() {
if(authuser > 5) { if(authuser > 5) {
return task.error(new Error('Unable to authenticate user ' + authorizationMgr.getUserId() + ', please sign in with Google.')); return task.error(new Error('Unable to authenticate user ' + authorizationMgr.getUserId() + ', please sign in with Google.'));
@ -179,6 +184,7 @@ define([
} }
}); });
} }
function oauthRedirect() { function oauthRedirect() {
if(immediate === true) { if(immediate === true) {
return task.chain(localAuthenticate); return task.chain(localAuthenticate);
@ -189,6 +195,7 @@ define([
task.error(new Error('Operation canceled.')); task.error(new Error('Operation canceled.'));
}); });
} }
function startAuthenticate() { function startAuthenticate() {
immediate = true; immediate = true;
if(authorizationMgr.token && authorizationMgr.isAuthorized(permission)) { if(authorizationMgr.token && authorizationMgr.isAuthorized(permission)) {
@ -200,9 +207,11 @@ define([
} }
task.chain(oauthRedirect); task.chain(oauthRedirect);
} }
startAuthenticate(); startAuthenticate();
}); });
} }
googleHelper.refreshGdriveToken = function(accountId) { googleHelper.refreshGdriveToken = function(accountId) {
var task = new AsyncTask(); var task = new AsyncTask();
connect(task); connect(task);
@ -357,6 +366,7 @@ define([
authenticate(task, 'gdrive', accountId); authenticate(task, 'gdrive', accountId);
task.onRun(function() { task.onRun(function() {
var nextPageToken; var nextPageToken;
function retrievePageOfChanges() { function retrievePageOfChanges() {
runWithToken(accountId, function() { runWithToken(accountId, function() {
var request; var request;
@ -391,6 +401,7 @@ define([
}); });
}); });
} }
task.chain(retrievePageOfChanges); task.chain(retrievePageOfChanges);
}); });
task.onSuccess(function() { task.onSuccess(function() {
@ -444,6 +455,7 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
task.chain(recursiveDownloadMetadata); task.chain(recursiveDownloadMetadata);
}); });
task.onSuccess(function() { task.onSuccess(function() {
@ -516,6 +528,7 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
task.chain(recursiveDownloadContent); task.chain(recursiveDownloadContent);
}); });
task.onSuccess(function() { task.onSuccess(function() {
@ -617,6 +630,7 @@ define([
} }
var pickerLoaded = false; var pickerLoaded = false;
function loadPicker(task) { function loadPicker(task) {
task.onRun(function() { task.onRun(function() {
if(pickerLoaded === true) { if(pickerLoaded === true) {
@ -649,12 +663,14 @@ define([
googleHelper.picker = function(callback, pickerType, accountId) { googleHelper.picker = function(callback, pickerType, accountId) {
var docs = []; var docs = [];
var picker; var picker;
function hidePicker() { function hidePicker() {
if(picker !== undefined) { if(picker !== undefined) {
picker.setVisible(false); picker.setVisible(false);
$(".modal-backdrop, .picker").remove(); $(".modal-backdrop, .picker").remove();
} }
} }
var task = new AsyncTask(); var task = new AsyncTask();
// Add some time for user to choose his files // Add some time for user to choose his files
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT; task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
@ -717,7 +733,7 @@ define([
} }
}); });
picker = pickerBuilder.build(); picker = pickerBuilder.build();
$(utils.createBackdrop()).click(function() { var $backdrop = $(utils.createBackdrop()).on('click.backdrop', function() {
hidePicker(); hidePicker();
task.chain(); task.chain();
}); });
@ -788,6 +804,7 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
function publish() { function publish() {
var url = "https://www.googleapis.com/blogger/v3/blogs/" + blogId + "/posts/" + postId; var url = "https://www.googleapis.com/blogger/v3/blogs/" + blogId + "/posts/" + postId;
if(isDraft) { if(isDraft) {
@ -819,6 +836,7 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
function getBlogId() { function getBlogId() {
if(blogId !== undefined) { if(blogId !== undefined) {
task.chain(uploadPost); task.chain(uploadPost);
@ -847,6 +865,7 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
task.chain(getBlogId); task.chain(getBlogId);
}); });
task.onSuccess(function() { task.onSuccess(function() {
@ -909,6 +928,7 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
function getBlogId() { function getBlogId() {
if(blogId !== undefined) { if(blogId !== undefined) {
task.chain(uploadPage); task.chain(uploadPage);
@ -937,6 +957,7 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
task.chain(getBlogId); task.chain(getBlogId);
}); });
task.onSuccess(function() { task.onSuccess(function() {

View File

@ -6,10 +6,9 @@ define([
"utils", "utils",
"storage", "storage",
"logger", "logger",
"settings",
"eventMgr", "eventMgr",
"classes/AsyncTask" "classes/AsyncTask"
], function(_, $, constants, core, utils, storage, logger, settings, eventMgr, AsyncTask) { ], function(_, $, constants, core, utils, storage, logger, eventMgr, AsyncTask) {
var connected = false; var connected = false;
var authenticated = true; var authenticated = true;
@ -60,7 +59,7 @@ define([
connect(task); connect(task);
authenticate(task); authenticate(task);
task.onRun(function() { task.onRun(function() {
var url = settings.teamserverURL + '/repo/' + repo + '/document'; var url = constants.TEAM_SERVER_URL + 'repo/' + repo + '/document';
var type = 'POST'; var type = 'POST';
if(id) { if(id) {
url += '/' + id; url += '/' + id;
@ -99,14 +98,14 @@ define([
task.enqueue(); task.enqueue();
}; };
teamserverHelper.checkChanges = function(repo, lastChangeId, accountId, callback) { teamserverHelper.checkChanges = function(repo, lastChangeId, callback) {
var changes; var changes;
var newChangeId = lastChangeId; var newChangeId = lastChangeId;
var task = new AsyncTask(); var task = new AsyncTask();
connect(task); connect(task);
authenticate(task); authenticate(task);
task.onRun(function() { task.onRun(function() {
var url = settings.teamserverURL + '/repo/' + repo + '/changes/'; var url = constants.TEAM_SERVER_URL + 'repo/' + repo + '/changes/';
var type = 'GET'; var type = 'GET';
if(lastChangeId) { if(lastChangeId) {
url += lastChangeId; url += lastChangeId;
@ -148,7 +147,7 @@ define([
return task.chain(); return task.chain();
} }
var id = ids[0]; var id = ids[0];
var url = settings.teamserverURL + '/repo/' + repo + '/document/' + id; var url = constants.TEAM_SERVER_URL + 'repo/' + repo + '/document/' + id;
$.ajax({ $.ajax({
url: url, url: url,
dataType: "json", dataType: "json",
@ -168,6 +167,7 @@ define([
handleError(error, task); handleError(error, task);
}); });
} }
task.chain(recursiveDownloadMetadata); task.chain(recursiveDownloadMetadata);
}); });
task.onSuccess(function() { task.onSuccess(function() {
@ -206,14 +206,16 @@ define([
task.error(new Error(errorMsg)); task.error(new Error(errorMsg));
} }
var $windowElt = $(window);
var origin = window.location.protocol + '//' + window.location.host;
teamserverHelper.picker = function(repo, callback) { teamserverHelper.picker = function(repo, callback) {
var docs = []; var docs = [];
var picker; var iframe;
function hidePicker() { function hidePicker() {
if(picker !== undefined) { if(iframe !== undefined) {
picker.setVisible(false); iframe.removeIframe();
$(".modal-backdrop, .picker").remove(); $windowElt.off('message.teamserver');
} }
} }
@ -222,8 +224,15 @@ define([
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT; task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
connect(task); connect(task);
task.onRun(function() { task.onRun(function() {
utils.iframe(constants.TEAM_SERVER_URL + 'index.html#/documentPicker', 800, 600); iframe = utils.iframe(constants.TEAM_SERVER_URL + 'teamserver.html#/documentPicker', 550, 500);
$windowElt.on('message.teamserver', function(evt) {
evt = evt.originalEvent;
if(evt.origin == origin && evt.data.status == 'DocumentPickerFinished') {
docs = evt.data.documents;
hidePicker();
task.chain(); task.chain();
}
});
}); });
task.onSuccess(function() { task.onSuccess(function() {
callback(undefined, docs); callback(undefined, docs);

View File

@ -116,7 +116,7 @@ define([
}; };
DomObject.prototype.createToggler = function(backdrop) { DomObject.prototype.createToggler = function(backdrop) {
var backdropElt; var $backdropElt;
var pushedEvents = 0; var pushedEvents = 0;
this.toggle = function(show) { this.toggle = function(show) {
if(show === this.isOpen) { if(show === this.isOpen) {
@ -126,7 +126,7 @@ define([
if(this.isOpen) { if(this.isOpen) {
this.$elt.addClass('panel-open').trigger('show.layout.toggle'); this.$elt.addClass('panel-open').trigger('show.layout.toggle');
if(backdrop) { if(backdrop) {
$(backdropElt = utils.createBackdrop(wrapperL1.elt)).click(_.bind(function() { $backdropElt = $(utils.createBackdrop(wrapperL1.elt)).on('click.backdrop', _.bind(function() {
this.toggle(false); this.toggle(false);
}, this)); }, this));
this.$elt.addClass('bring-to-front'); this.$elt.addClass('bring-to-front');
@ -139,8 +139,11 @@ define([
} }
else { else {
this.$elt.trigger('hide.layout.toggle'); this.$elt.trigger('hide.layout.toggle');
backdropElt && backdropElt.removeBackdrop(); if($backdropElt) {
backdropElt = undefined; $backdropElt.off('click.backdrop');
$backdropElt[0].removeBackdrop();
$backdropElt = undefined;
}
transitionEndCallbacks.push(_.bind(function() { transitionEndCallbacks.push(_.bind(function() {
if(--pushedEvents === 0) { if(--pushedEvents === 0) {
!this.isOpen && this.$elt.removeClass('panel-open bring-to-front').trigger('hidden.layout.toggle'); !this.isOpen && this.$elt.removeClass('panel-open bring-to-front').trigger('hidden.layout.toggle');

View File

@ -14,7 +14,7 @@ define([
], function($, _, constants, utils, storage, logger, Provider, settings, eventMgr, fileMgr, editor, teamserverHelper) { ], function($, _, constants, utils, storage, logger, Provider, settings, eventMgr, fileMgr, editor, teamserverHelper) {
return function(providerId, providerName) { return function(providerId, providerName) {
var repo = 'teamserver'; var repo = 'test';
var teamserverProvider = new Provider(providerId, providerName); var teamserverProvider = new Provider(providerId, providerName);
@ -131,8 +131,8 @@ define([
return callback(error); return callback(error);
} }
var interestingChanges = []; var interestingChanges = [];
_.each(changes, function(change) { _.each(changes, function(change, id) {
var syncIndex = createSyncIndex(change.id); var syncIndex = createSyncIndex(id);
var fileDesc = fileMgr.getFileFromSyncIndex(syncIndex); var fileDesc = fileMgr.getFileFromSyncIndex(syncIndex);
var syncAttributes = fileDesc && fileDesc.syncLocations[syncIndex]; var syncAttributes = fileDesc && fileDesc.syncLocations[syncIndex];
if(!syncAttributes) { if(!syncAttributes) {
@ -151,7 +151,7 @@ define([
interestingChanges.push(change); interestingChanges.push(change);
} }
}); });
teamserverHelper.downloadContent(repo, interestingChanges, function(error, changes) { teamserverHelper.download(repo, interestingChanges, function(error, changes) {
if(error) { if(error) {
return callback(error); return callback(error);
} }

View File

@ -192,18 +192,27 @@ body {
.translate(0, 0); .translate(0, 0);
} }
.modal-content { }
background-color: @secondary-bg-light;
}
.modal-body { .modal-content {
background-color: @secondary-bg-light;
}
.modal-body {
background-color: @secondary-bg-lighter; background-color: @secondary-bg-lighter;
padding-bottom: 30px; padding-bottom: 30px;
} }
.modal-footer { .modal-footer {
background-color: @secondary-bg-light;
margin-top: 0; margin-top: 0;
} }
.modal-iframe {
display: block;
margin: 30px auto 0;
z-index: 1040;
border-radius: 0;
} }
a { a {

View File

@ -308,20 +308,34 @@ define([
].join("")); ].join(""));
}; };
utils.iframe = function(url, width, height, css) { var $windowElt = $(window);
$("<iframe src=\"" + url + "\">") utils.iframe = function(url, width, height) {
.attr("id", "remidDialogIframe") var $backdropElt = $(utils.createBackdrop());
.attr("width", width) var result = crel('iframe', {
.attr("height", height) src: url,
//.attr("scrolling", options.iframeScrolling) frameborder: 0,
.attr("frameborder", "0") class: 'modal-content modal-iframe'
.css("position", "fixed") });
.css(css || {}) document.body.appendChild(result);
//.css("border", options.iframeBorder) function placeIframe() {
//.css("border-radius", options.iframeBorderRadius) var actualWidth = window.innerWidth - 20;
//.css("background", options.iframeBackground) actualWidth > width && (actualWidth = width);
//.css("z-index", options.iframeZindex) var actualHeight = window.innerHeight - 50;
.appendTo(document.body); actualHeight > height && (actualHeight = height);
result.setAttribute('width', actualWidth);
result.setAttribute('height', actualHeight);
}
placeIframe();
$windowElt.on('resize.iframe', placeIframe);
function removeIframe() {
$backdropElt.off('click.backdrop');
$backdropElt[0].removeBackdrop();
$windowElt.off('resize.iframe');
result.parentNode.removeChild(result);
}
result.removeIframe = removeIframe;
$backdropElt.on('click.backdrop', removeIframe);
return result;
}; };
// Shows a dialog to force the user to click a button before opening oauth popup // Shows a dialog to force the user to click a button before opening oauth popup