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/";

File diff suppressed because it is too large Load Diff

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;
@ -35,8 +34,8 @@ define([
url: constants.TEAM_SERVER_URL + 'ping', url: constants.TEAM_SERVER_URL + 'ping',
timeout: constants.AJAX_TIMEOUT timeout: constants.AJAX_TIMEOUT
}).done(function() { }).done(function() {
task.chain(); task.chain();
}).fail(function(jqXHR) { }).fail(function(jqXHR) {
var error = { var error = {
code: jqXHR.status, code: jqXHR.status,
message: jqXHR.statusText message: jqXHR.statusText
@ -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;
@ -77,7 +76,7 @@ define([
timeout: constants.AJAX_TIMEOUT timeout: constants.AJAX_TIMEOUT
}).done(function(data) { }).done(function(data) {
result = data; result = data;
task.chain(); task.chain();
}).fail(function(jqXHR) { }).fail(function(jqXHR) {
var error = { var error = {
code: jqXHR.status, code: jqXHR.status,
@ -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;
@ -119,7 +118,7 @@ define([
}).done(function(data) { }).done(function(data) {
newChangeId = data.newChangeId; newChangeId = data.newChangeId;
changes = data.changes; changes = data.changes;
task.chain(); task.chain();
}).fail(function(jqXHR) { }).fail(function(jqXHR) {
var error = { var error = {
code: jqXHR.status, code: jqXHR.status,
@ -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');
} }
} }
@ -221,10 +223,17 @@ define([
// 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;
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);
task.chain(); $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() { 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-lighter; background-color: @secondary-bg-light;
padding-bottom: 30px; }
}
.modal-footer { .modal-body {
margin-top: 0; background-color: @secondary-bg-lighter;
} padding-bottom: 30px;
}
.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 { a {

View File

@ -308,21 +308,35 @@ 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
var redirectCallbackConfirm; var redirectCallbackConfirm;