2011-08-11 02:35:01 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2011, Google Inc.
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
|
|
|
* Neither the name of Google Inc. nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived from
|
|
|
|
this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
Refine.GDataSourceUI = function(controller) {
|
|
|
|
this._controller = controller;
|
|
|
|
};
|
|
|
|
|
|
|
|
Refine.GDataSourceUI.prototype.attachUI = function(body) {
|
|
|
|
this._body = body;
|
|
|
|
|
|
|
|
this._body.html(DOM.loadHTML("gdata", "scripts/index/import-from-gdata-form.html"));
|
|
|
|
this._elmts = DOM.bind(this._body);
|
|
|
|
|
2018-11-21 16:24:57 +01:00
|
|
|
$('#gdata-title').text($.i18n._('gdata-import/title'));
|
|
|
|
$('#gdata-import').html($.i18n._('gdata-import/import-by-url'));
|
2013-06-27 17:25:53 +02:00
|
|
|
$('#gdata-next').html($.i18n._("gdata-import")["next->"]);
|
2018-11-21 16:24:57 +01:00
|
|
|
$('#gdata-auth-doc').text($.i18n._('gdata-import/auth-doc'));
|
|
|
|
$('#gdata-please').text($.i18n._('gdata-import/please'));
|
|
|
|
$('#gdata-signin-btn').text($.i18n._('gdata-import/sign-in'));
|
|
|
|
$('#gdata-access-data').text($.i18n._('gdata-import/access-data'));
|
|
|
|
$('#gdata-retrieving').text($.i18n._('gdata-import/retrieving'));
|
|
|
|
$('#gdata-signout').text($.i18n._('gdata-import/sign-out'));
|
|
|
|
$('#gdata-resignin').text($.i18n._('gdata-import/re-sign-in'));
|
|
|
|
$('#gdata-another-account').text($.i18n._('gdata-import/another-account'));
|
2013-06-27 17:25:53 +02:00
|
|
|
|
2011-10-05 06:39:42 +02:00
|
|
|
var self = this;
|
2011-08-11 02:35:01 +02:00
|
|
|
this._body.find('.gdata-signin.button').click(function() {
|
2011-10-05 06:39:42 +02:00
|
|
|
GdataExtension.showAuthorizationDialog(
|
|
|
|
function() {
|
|
|
|
self._listDocuments();
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
self._body.find('.gdata-page').hide();
|
|
|
|
self._elmts.signinPage.show();
|
|
|
|
}
|
2011-08-11 02:35:01 +02:00
|
|
|
);
|
|
|
|
});
|
2011-11-16 08:34:41 +01:00
|
|
|
this._body.find('.gdata-signout.button').click(function() {
|
2012-10-13 19:47:08 +02:00
|
|
|
$.get("command/gdata/deauthorize" );
|
2011-11-16 08:34:41 +01:00
|
|
|
self._body.find('.gdata-page').hide();
|
|
|
|
self._elmts.signinPage.show();
|
|
|
|
});
|
|
|
|
|
2011-11-17 02:32:28 +01:00
|
|
|
this._elmts.urlNextButton.click(function(evt) {
|
|
|
|
var url = $.trim(self._elmts.urlInput[0].value);
|
|
|
|
if (url.length === 0) {
|
2018-11-21 16:24:57 +01:00
|
|
|
window.alert($.i18n._('gdata-source/alert-url'));
|
2011-11-16 08:34:41 +01:00
|
|
|
} else {
|
2011-11-17 19:52:14 +01:00
|
|
|
var doc = {};
|
2011-11-17 02:32:28 +01:00
|
|
|
doc.docSelfLink = url;
|
|
|
|
if (doc.docSelfLink.contains('spreadsheet')) { // TODO: fragile?
|
|
|
|
doc.type = 'spreadsheet';
|
|
|
|
} else {
|
|
|
|
doc.type = 'table';
|
|
|
|
}
|
2018-02-25 18:00:40 +01:00
|
|
|
|
|
|
|
if (GdataExtension.isAuthorized()) {
|
|
|
|
self._controller.startImportingDocument(doc);
|
|
|
|
} else {
|
|
|
|
var fn = self._controller.startImportingDocument;
|
|
|
|
GdataExtension.showAuthorizationDialog(fn.bind(self._controller, doc));
|
|
|
|
}
|
2011-11-17 02:32:28 +01:00
|
|
|
}
|
|
|
|
});
|
2011-11-16 08:34:41 +01:00
|
|
|
|
2011-08-11 02:35:01 +02:00
|
|
|
this._body.find('.gdata-page').hide();
|
|
|
|
this._elmts.signinPage.show();
|
|
|
|
|
2011-10-05 06:39:42 +02:00
|
|
|
if (GdataExtension.isAuthorized()) {
|
2011-08-11 02:35:01 +02:00
|
|
|
this._listDocuments();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Refine.GDataSourceUI.prototype.focus = function() {
|
|
|
|
};
|
|
|
|
|
|
|
|
Refine.GDataSourceUI.prototype._listDocuments = function() {
|
|
|
|
this._body.find('.gdata-page').hide();
|
|
|
|
this._elmts.progressPage.show();
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
$.post(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/importing-controller?" + $.param({
|
2011-08-11 02:35:01 +02:00
|
|
|
"controller": "gdata/gdata-importing-controller",
|
|
|
|
"subCommand": "list-documents"
|
|
|
|
}),
|
|
|
|
null,
|
|
|
|
function(o) {
|
|
|
|
self._renderDocuments(o);
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Refine.GDataSourceUI.prototype._renderDocuments = function(o) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this._elmts.listingContainer.empty();
|
|
|
|
|
|
|
|
var table = $(
|
|
|
|
'<table><tr>' +
|
|
|
|
'<th></th>' + // starred
|
2018-11-21 16:24:57 +01:00
|
|
|
'<th>'+$.i18n._('gdata-source/type')+'</th>' +
|
|
|
|
'<th>'+$.i18n._('gdata-source/title')+'</th>' +
|
|
|
|
'<th>'+$.i18n._('gdata-source/authors')+'</th>' +
|
|
|
|
'<th>'+$.i18n._('gdata-source/updated')+'</th>' +
|
2011-08-11 02:35:01 +02:00
|
|
|
'</tr></table>'
|
|
|
|
).appendTo(this._elmts.listingContainer)[0];
|
|
|
|
|
|
|
|
var renderDocument = function(doc) {
|
|
|
|
var tr = table.insertRow(table.rows.length);
|
|
|
|
|
|
|
|
var td = tr.insertCell(tr.cells.length);
|
|
|
|
if (doc.isStarred) {
|
|
|
|
$('<img>').attr('src', 'images/star.png').appendTo(td);
|
|
|
|
}
|
2011-08-12 23:32:45 +02:00
|
|
|
|
|
|
|
td = tr.insertCell(tr.cells.length);
|
|
|
|
$('<span>').text(doc.type).appendTo(td);
|
|
|
|
|
2011-08-11 02:35:01 +02:00
|
|
|
td = tr.insertCell(tr.cells.length);
|
2013-09-03 00:56:55 +02:00
|
|
|
$('<a>')
|
2011-08-11 02:35:01 +02:00
|
|
|
.addClass('gdata-doc-title')
|
|
|
|
.attr('href', 'javascript:{}')
|
|
|
|
.text(doc.title)
|
|
|
|
.appendTo(td)
|
|
|
|
.click(function(evt) {
|
|
|
|
self._controller.startImportingDocument(doc);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('<a>')
|
|
|
|
.addClass('gdata-doc-preview')
|
|
|
|
.attr('href', doc.docLink)
|
|
|
|
.attr('target', '_blank')
|
|
|
|
.text('preview')
|
|
|
|
.appendTo(td);
|
|
|
|
|
|
|
|
td = tr.insertCell(tr.cells.length);
|
|
|
|
$('<span>')
|
2011-08-12 23:32:45 +02:00
|
|
|
.addClass('gdata-doc-authors')
|
2011-09-15 23:40:40 +02:00
|
|
|
.text((doc.authors) ? doc.authors.join(', ') : '<unknown>')
|
2011-08-11 02:35:01 +02:00
|
|
|
.appendTo(td);
|
|
|
|
|
|
|
|
td = tr.insertCell(tr.cells.length);
|
2011-09-15 23:40:40 +02:00
|
|
|
$('<span>')
|
|
|
|
.addClass('gdata-doc-date')
|
|
|
|
.text((doc.updated) ? formatRelativeDate(doc.updated) : '<unknown>')
|
|
|
|
.attr('title', (doc.updated) ? doc.updated : '<unknown>')
|
|
|
|
.appendTo(td);
|
2011-08-11 02:35:01 +02:00
|
|
|
};
|
2011-08-12 23:32:45 +02:00
|
|
|
|
|
|
|
var docs = o.documents;
|
2011-09-16 02:34:00 +02:00
|
|
|
$.each(docs, function() {
|
|
|
|
this.updatedDate = (this.updated) ? new Date(this.updated) : null;
|
|
|
|
this.updatedDateTime = (this.updatedDate) ? this.updatedDate.getTime() : 0;
|
|
|
|
});
|
|
|
|
docs.sort(function(a, b) { return b.updatedDateTime - a.updatedDateTime; });
|
2011-08-12 23:32:45 +02:00
|
|
|
|
|
|
|
for (var i = 0; i < docs.length; i++) {
|
|
|
|
renderDocument(docs[i]);
|
2011-08-11 02:35:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this._body.find('.gdata-page').hide();
|
|
|
|
this._elmts.listingPage.show();
|
|
|
|
};
|