2010-10-20 20:11:15 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2010, 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:
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions of source code must retain the above copyright
|
2010-10-20 20:11:15 +02:00
|
|
|
notice, this list of conditions and the following disclaimer.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions in binary form must reproduce the above
|
2010-10-20 20:11:15 +02:00
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Neither the name of Google Inc. nor the names of its
|
2010-10-20 20:11:15 +02:00
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2012-10-19 01:40:31 +02:00
|
|
|
var OpenRefineVersion;
|
2010-10-22 03:43:56 +02:00
|
|
|
|
2011-08-02 05:34:47 +02:00
|
|
|
var Refine = {
|
2011-08-04 22:37:14 +02:00
|
|
|
actionAreas: []
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2019-10-11 16:30:54 +02:00
|
|
|
// Requests a CSRF token and calls the supplied callback
|
|
|
|
// with the token
|
2019-10-15 13:04:17 +02:00
|
|
|
Refine.wrapCSRF = function(onCSRF) {
|
|
|
|
$.get(
|
|
|
|
"command/core/get-csrf-token",
|
|
|
|
{},
|
|
|
|
function(response) {
|
|
|
|
onCSRF(response['token']);
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-10-11 16:30:54 +02:00
|
|
|
// Performs a POST request where an additional CSRF token
|
|
|
|
// is supplied in the POST data. The arguments match those
|
|
|
|
// of $.post().
|
2019-10-14 15:04:38 +02:00
|
|
|
Refine.postCSRF = function(url, data, success, dataType, failCallback) {
|
|
|
|
return Refine.wrapCSRF(function(token) {
|
2019-10-15 13:04:17 +02:00
|
|
|
var fullData = data || {};
|
2019-10-17 12:44:57 +02:00
|
|
|
if (typeof fullData == 'string') {
|
|
|
|
fullData = fullData + "&" + $.param({csrf_token: token});
|
2019-10-17 11:42:05 +02:00
|
|
|
} else {
|
|
|
|
fullData['csrf_token'] = token;
|
|
|
|
}
|
2019-10-14 15:04:38 +02:00
|
|
|
var req = $.post(url, fullData, success, dataType);
|
|
|
|
if (failCallback !== undefined) {
|
|
|
|
req.fail(failCallback);
|
|
|
|
}
|
2019-10-15 13:04:17 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-07-03 15:05:39 +02:00
|
|
|
var lang = (navigator.language|| navigator.userLanguage).split("-")[0];
|
2013-07-02 13:40:50 +02:00
|
|
|
var dictionary = "";
|
|
|
|
$.ajax({
|
2014-12-03 14:52:06 +01:00
|
|
|
url : "command/core/load-language?",
|
2013-07-02 13:40:50 +02:00
|
|
|
type : "POST",
|
|
|
|
async : false,
|
|
|
|
data : {
|
2013-07-31 06:31:31 +02:00
|
|
|
module : "core",
|
|
|
|
// lang : lang
|
2013-07-02 13:40:50 +02:00
|
|
|
},
|
|
|
|
success : function(data) {
|
2017-10-23 21:39:46 +02:00
|
|
|
dictionary = data['dictionary'];
|
|
|
|
lang = data['lang'];
|
2013-07-02 13:40:50 +02:00
|
|
|
}
|
|
|
|
});
|
2017-10-23 21:39:46 +02:00
|
|
|
$.i18n().load(dictionary, lang);
|
2018-11-21 19:26:55 +01:00
|
|
|
$.i18n({ locale: lang });
|
2013-07-02 13:40:50 +02:00
|
|
|
// End internationalization
|
|
|
|
|
2011-08-02 05:34:47 +02:00
|
|
|
Refine.selectActionArea = function(id) {
|
2011-08-04 22:37:14 +02:00
|
|
|
$('.action-area-tab').removeClass('selected');
|
2011-08-12 21:15:58 +02:00
|
|
|
$('.action-area-tab-body').css('visibility', 'hidden').css('z-index', '50');
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
for (var i = 0; i < Refine.actionAreas.length; i++) {
|
|
|
|
var actionArea = Refine.actionAreas[i];
|
|
|
|
if (id == actionArea.id) {
|
|
|
|
actionArea.tabElmt.addClass('selected');
|
2011-10-08 01:44:11 +02:00
|
|
|
actionArea.bodyElmt.css('visibility', 'visible').css('z-index', '55');
|
2010-02-03 07:23:40 +01:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
2010-02-03 07:23:40 +01:00
|
|
|
|
2011-08-02 05:34:47 +02:00
|
|
|
$(function() {
|
2017-09-27 12:00:47 +02:00
|
|
|
var isThereNewRelease = function(thisVer,latestVer) {
|
|
|
|
// Assumes Semantic Version numbering format of form X.Y.Z where X, Y, and Z are non-negative integer
|
|
|
|
// Ignores any trailing letters e.g. 2.7.1-rc.1 will be interpreted as equivalent to 2.7.1
|
|
|
|
if(thisVer == latestVer) {
|
2011-08-04 22:37:14 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-09-27 12:00:47 +02:00
|
|
|
var thisVerParts = thisVer.split(".");
|
|
|
|
var latestVerParts = latestVer.split(".");
|
|
|
|
while(thisVerParts.length < 3)
|
|
|
|
thisVerParts.push(0);
|
|
|
|
while(latestVerParts.length < 3)
|
2017-09-27 12:47:07 +02:00
|
|
|
latestVerParts.push(0);
|
2017-09-27 12:00:47 +02:00
|
|
|
|
|
|
|
for(var i=0; i<3; i++) {
|
2017-09-27 12:47:07 +02:00
|
|
|
var thisVerPartInt = parseInt(thisVerParts[i],10);
|
|
|
|
var latestVerPartInt = parseInt(latestVerParts[i],10);
|
|
|
|
if(thisVerPartInt == latestVerPartInt) {
|
2017-09-27 12:00:47 +02:00
|
|
|
continue;
|
|
|
|
} else {
|
2017-09-27 13:22:59 +02:00
|
|
|
return !(thisVerPartInt > latestVerPartInt);
|
2017-09-27 12:00:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2011-08-04 22:37:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var showVersion = function() {
|
|
|
|
$.getJSON(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/get-version",
|
2010-10-18 06:18:09 +02:00
|
|
|
null,
|
|
|
|
function(data) {
|
2012-10-19 01:40:31 +02:00
|
|
|
OpenRefineVersion = data;
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2020-08-04 10:10:38 +02:00
|
|
|
$("#openrefine-version").text($.i18n('core-index/version', OpenRefineVersion.full_version));
|
2017-09-27 12:00:47 +02:00
|
|
|
|
2017-09-27 12:47:07 +02:00
|
|
|
$.getJSON("https://api.github.com/repos/openrefine/openrefine/releases/latest",
|
2017-09-27 12:00:47 +02:00
|
|
|
function( data ) {
|
|
|
|
var latestVersion = data.tag_name;
|
|
|
|
var latestVersionName = data.name;
|
|
|
|
var latestVersionUrl = data.html_url;
|
|
|
|
var thisVersion = OpenRefineVersion.version;
|
|
|
|
|
|
|
|
if(latestVersion.startsWith("v")) {
|
|
|
|
latestVersion = latestVersion.substr(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isThereNewRelease(thisVersion,latestVersion)) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var container = $('<div id="notification-container">')
|
2011-10-08 01:44:11 +02:00
|
|
|
.appendTo(document.body);
|
2011-08-04 22:37:14 +02:00
|
|
|
var notification = $('<div id="notification">')
|
2018-11-21 18:30:00 +01:00
|
|
|
.text($.i18n('core-index/new-version')+' ')
|
2011-10-08 01:44:11 +02:00
|
|
|
.appendTo(container);
|
2011-08-04 22:37:14 +02:00
|
|
|
$('<a>')
|
|
|
|
.addClass('notification-action')
|
2017-09-27 12:00:47 +02:00
|
|
|
.attr("href", latestVersionUrl)
|
2017-09-27 13:22:59 +02:00
|
|
|
.attr("target", "_blank")
|
2020-08-04 10:10:38 +02:00
|
|
|
.text($.i18n('core-index/download-now', latestVersionName))
|
2011-08-04 22:37:14 +02:00
|
|
|
.appendTo(notification);
|
|
|
|
}
|
2017-09-27 12:00:47 +02:00
|
|
|
});
|
2010-10-18 06:18:09 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
var resize = function() {
|
|
|
|
var leftPanelWidth = 150;
|
|
|
|
// px
|
|
|
|
var width = $(window).width();
|
|
|
|
var height = $(window).height();
|
|
|
|
var headerHeight = $('#header').outerHeight();
|
|
|
|
var panelHeight = height - headerHeight;
|
|
|
|
|
|
|
|
$('.main-layout-panel')
|
|
|
|
.css("top", headerHeight + "px")
|
|
|
|
.css("bottom", "0px")
|
|
|
|
.css("height", panelHeight + "px")
|
|
|
|
.css("visibility", "visible");
|
|
|
|
|
|
|
|
$('#left-panel')
|
|
|
|
.css("left", "0px")
|
|
|
|
.css("width", leftPanelWidth + "px");
|
|
|
|
var leftPanelBodyHPaddings = 10;
|
|
|
|
// px
|
|
|
|
var leftPanelBodyVPaddings = 0;
|
|
|
|
// px
|
|
|
|
$('#left-panel-body')
|
|
|
|
.css("margin-left", leftPanelBodyHPaddings + "px")
|
|
|
|
.css("margin-top", leftPanelBodyVPaddings + "px")
|
|
|
|
.css("width", ($('#left-panel').width() - leftPanelBodyHPaddings) + "px")
|
|
|
|
.css("height", ($('#left-panel').height() - leftPanelBodyVPaddings) + "px");
|
|
|
|
|
|
|
|
$('#right-panel')
|
|
|
|
.css("left", leftPanelWidth + "px")
|
|
|
|
.css("width", (width - leftPanelWidth) + "px");
|
|
|
|
|
|
|
|
var rightPanelBodyHPaddings = 5;
|
|
|
|
// px
|
|
|
|
var rightPanelBodyVPaddings = 5;
|
|
|
|
// px
|
|
|
|
$('#right-panel-body')
|
|
|
|
.css("margin-left", rightPanelBodyHPaddings + "px")
|
|
|
|
.css("margin-top", rightPanelBodyVPaddings + "px")
|
|
|
|
.css("width", ($('#right-panel').width() - rightPanelBodyHPaddings) + "px")
|
|
|
|
.css("height", ($('#right-panel').height() - rightPanelBodyVPaddings) + "px");
|
2011-08-08 01:26:51 +02:00
|
|
|
|
|
|
|
for (var i = 0; i < Refine.actionAreas.length; i++) {
|
|
|
|
Refine.actionAreas[i].ui.resize();
|
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
};
|
|
|
|
$(window).bind("resize", resize);
|
2011-08-08 01:26:51 +02:00
|
|
|
window.setTimeout(resize, 100); // for Chrome, give the window some time to layout first
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
var renderActionArea = function(actionArea) {
|
|
|
|
actionArea.bodyElmt = $('<div>')
|
|
|
|
.addClass('action-area-tab-body')
|
|
|
|
.appendTo('#right-panel-body');
|
|
|
|
|
|
|
|
actionArea.tabElmt = $('<li>')
|
|
|
|
.addClass('action-area-tab')
|
|
|
|
.text(actionArea.label)
|
|
|
|
.appendTo($('#action-area-tabs'))
|
|
|
|
.click(function() {
|
|
|
|
Refine.selectActionArea(actionArea.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
actionArea.ui = new actionArea.uiClass(actionArea.bodyElmt);
|
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < Refine.actionAreas.length; i++) {
|
|
|
|
renderActionArea(Refine.actionAreas[i]);
|
|
|
|
}
|
|
|
|
Refine.selectActionArea('create-project');
|
2013-07-11 15:01:45 +02:00
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
$("#slogan").text($.i18n('core-index/slogan')+".");
|
|
|
|
$("#or-index-pref").text($.i18n('core-index/preferences'));
|
|
|
|
$("#or-index-help").text($.i18n('core-index/help'));
|
|
|
|
$("#or-index-about").text($.i18n('core-index/about'));
|
|
|
|
$("#or-index-noProj").text($.i18n('core-index/no-proj')+".");
|
|
|
|
$("#or-index-try").text($.i18n('core-index/try-these'));
|
|
|
|
$("#or-index-sample").text($.i18n('core-index/sample-data'));
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
showVersion();
|
2011-08-02 05:34:47 +02:00
|
|
|
});
|