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.SSH_PROXY_URL = "https://stackedit-ssh-proxy.herokuapp.com/";
constants.HTMLTOPDF_URL = "https://stackedit-htmltopdf.herokuapp.com/";
constants.TEAM_SERVER_URL = "http://localhost:11583/";
constants.TEAM_SERVER_URL = "/";
// Site dependent
constants.BASE_URL = "http://localhost/";

View File

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

View File

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

View File

@ -116,7 +116,7 @@ define([
};
DomObject.prototype.createToggler = function(backdrop) {
var backdropElt;
var $backdropElt;
var pushedEvents = 0;
this.toggle = function(show) {
if(show === this.isOpen) {
@ -126,7 +126,7 @@ define([
if(this.isOpen) {
this.$elt.addClass('panel-open').trigger('show.layout.toggle');
if(backdrop) {
$(backdropElt = utils.createBackdrop(wrapperL1.elt)).click(_.bind(function() {
$backdropElt = $(utils.createBackdrop(wrapperL1.elt)).on('click.backdrop', _.bind(function() {
this.toggle(false);
}, this));
this.$elt.addClass('bring-to-front');
@ -139,8 +139,11 @@ define([
}
else {
this.$elt.trigger('hide.layout.toggle');
backdropElt && backdropElt.removeBackdrop();
backdropElt = undefined;
if($backdropElt) {
$backdropElt.off('click.backdrop');
$backdropElt[0].removeBackdrop();
$backdropElt = undefined;
}
transitionEndCallbacks.push(_.bind(function() {
if(--pushedEvents === 0) {
!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) {
return function(providerId, providerName) {
var repo = 'teamserver';
var repo = 'test';
var teamserverProvider = new Provider(providerId, providerName);
@ -131,8 +131,8 @@ define([
return callback(error);
}
var interestingChanges = [];
_.each(changes, function(change) {
var syncIndex = createSyncIndex(change.id);
_.each(changes, function(change, id) {
var syncIndex = createSyncIndex(id);
var fileDesc = fileMgr.getFileFromSyncIndex(syncIndex);
var syncAttributes = fileDesc && fileDesc.syncLocations[syncIndex];
if(!syncAttributes) {
@ -151,7 +151,7 @@ define([
interestingChanges.push(change);
}
});
teamserverHelper.downloadContent(repo, interestingChanges, function(error, changes) {
teamserverHelper.download(repo, interestingChanges, function(error, changes) {
if(error) {
return callback(error);
}

View File

@ -192,18 +192,27 @@ body {
.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;
padding-bottom: 30px;
}
}
.modal-footer {
.modal-footer {
background-color: @secondary-bg-light;
margin-top: 0;
}
}
.modal-iframe {
display: block;
margin: 30px auto 0;
z-index: 1040;
border-radius: 0;
}
a {

View File

@ -308,20 +308,34 @@ define([
].join(""));
};
utils.iframe = function(url, width, height, css) {
$("<iframe src=\"" + url + "\">")
.attr("id", "remidDialogIframe")
.attr("width", width)
.attr("height", height)
//.attr("scrolling", options.iframeScrolling)
.attr("frameborder", "0")
.css("position", "fixed")
.css(css || {})
//.css("border", options.iframeBorder)
//.css("border-radius", options.iframeBorderRadius)
//.css("background", options.iframeBackground)
//.css("z-index", options.iframeZindex)
.appendTo(document.body);
var $windowElt = $(window);
utils.iframe = function(url, width, height) {
var $backdropElt = $(utils.createBackdrop());
var result = crel('iframe', {
src: url,
frameborder: 0,
class: 'modal-content modal-iframe'
});
document.body.appendChild(result);
function placeIframe() {
var actualWidth = window.innerWidth - 20;
actualWidth > width && (actualWidth = width);
var actualHeight = window.innerHeight - 50;
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