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

File diff suppressed because it is too large Load Diff

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;
@ -35,8 +34,8 @@ define([
url: constants.TEAM_SERVER_URL + 'ping',
timeout: constants.AJAX_TIMEOUT
}).done(function() {
task.chain();
}).fail(function(jqXHR) {
task.chain();
}).fail(function(jqXHR) {
var error = {
code: jqXHR.status,
message: jqXHR.statusText
@ -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;
@ -77,7 +76,7 @@ define([
timeout: constants.AJAX_TIMEOUT
}).done(function(data) {
result = data;
task.chain();
task.chain();
}).fail(function(jqXHR) {
var error = {
code: jqXHR.status,
@ -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;
@ -119,7 +118,7 @@ define([
}).done(function(data) {
newChangeId = data.newChangeId;
changes = data.changes;
task.chain();
task.chain();
}).fail(function(jqXHR) {
var error = {
code: jqXHR.status,
@ -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');
}
}
@ -221,10 +223,17 @@ define([
// Add some time for user to choose his files
task.timeout = constants.ASYNC_TASK_LONG_TIMEOUT;
connect(task);
task.onRun(function() {
utils.iframe(constants.TEAM_SERVER_URL + 'index.html#/documentPicker', 800, 600);
task.chain();
});
task.onRun(function() {
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 {
background-color: @secondary-bg-lighter;
padding-bottom: 30px;
}
.modal-content {
background-color: @secondary-bg-light;
}
.modal-footer {
margin-top: 0;
}
.modal-body {
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 {

View File

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