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.
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
*/
|
2010-10-20 20:11:15 +02:00
|
|
|
|
2010-01-26 06:17:14 +01:00
|
|
|
var theProject;
|
2020-06-18 10:35:37 +02:00
|
|
|
var thePreferences;
|
2010-01-26 06:17:14 +01:00
|
|
|
var ui = {};
|
|
|
|
|
2014-07-03 15:05:39 +02:00
|
|
|
var lang = (navigator.language|| navigator.userLanguage).split("-")[0];
|
2013-07-04 11:51:04 +02:00
|
|
|
var dictionary = "";
|
|
|
|
$.ajax({
|
2014-12-03 14:52:06 +01:00
|
|
|
url : "command/core/load-language?",
|
2013-07-04 11:51:04 +02:00
|
|
|
type : "POST",
|
|
|
|
async : false,
|
|
|
|
data : {
|
2013-07-31 06:31:31 +02:00
|
|
|
module : "core",
|
|
|
|
// lang : lang
|
2013-07-04 11:51:04 +02:00
|
|
|
},
|
|
|
|
success : function(data) {
|
2017-10-23 21:39:46 +02:00
|
|
|
dictionary = data['dictionary'];
|
|
|
|
lang = data['lang'];
|
2013-07-04 11:51:04 +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-04 11:51:04 +02:00
|
|
|
// End internationalization
|
|
|
|
|
2020-03-12 11:57:42 +01:00
|
|
|
var Refine = {};
|
2010-02-26 22:56:41 +01:00
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.reportException = function(e) {
|
2011-08-04 22:37:14 +02:00
|
|
|
if (window.console) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
2010-02-26 22:56:41 +01:00
|
|
|
};
|
|
|
|
|
2010-04-09 03:48:50 +02:00
|
|
|
function resize() {
|
2021-04-16 18:06:04 +02:00
|
|
|
var leftPanelWidth = JSON.parse(Refine.getPreference("ui.browsing.facetsHistoryPanelWidth", 300));
|
|
|
|
if(typeof leftPanelWidth != "number" || leftPanelWidth < 200 || leftPanelWidth > 500) {
|
|
|
|
leftPanelWidth = 300;
|
|
|
|
}
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
var width = $(window).width();
|
|
|
|
var top = $("#header").outerHeight();
|
|
|
|
var height = $(window).height() - top;
|
2020-05-30 13:01:26 +02:00
|
|
|
|
|
|
|
if (ui.leftPanelDiv.css('display') == "none") { leftPanelWidth = 0; }
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
var leftPanelPaddings = ui.leftPanelDiv.outerHeight(true) - ui.leftPanelDiv.height();
|
|
|
|
ui.leftPanelDiv
|
|
|
|
.css("top", top + "px")
|
|
|
|
.css("left", "0px")
|
|
|
|
.css("height", (height - leftPanelPaddings) + "px")
|
|
|
|
.css("width", leftPanelWidth + "px");
|
|
|
|
|
|
|
|
var leftPanelTabsPaddings = ui.leftPanelTabs.outerHeight(true) - ui.leftPanelTabs.height();
|
|
|
|
ui.leftPanelTabs.height(ui.leftPanelDiv.height() - leftPanelTabsPaddings);
|
|
|
|
|
|
|
|
var rightPanelVPaddings = ui.rightPanelDiv.outerHeight(true) - ui.rightPanelDiv.height();
|
|
|
|
var rightPanelHPaddings = ui.rightPanelDiv.outerWidth(true) - ui.rightPanelDiv.width();
|
|
|
|
ui.rightPanelDiv
|
|
|
|
.css("top", top + "px")
|
|
|
|
.css("left", leftPanelWidth + "px")
|
|
|
|
.css("height", (height - rightPanelVPaddings) + "px")
|
|
|
|
.css("width", (width - leftPanelWidth - rightPanelHPaddings) + "px");
|
|
|
|
|
|
|
|
ui.viewPanelDiv.height((height - ui.toolPanelDiv.outerHeight() - rightPanelVPaddings) + "px");
|
|
|
|
|
|
|
|
var processPanelWidth = 400;
|
|
|
|
ui.processPanelDiv
|
|
|
|
.css("width", processPanelWidth + "px")
|
|
|
|
.css("left", Math.floor((width - processPanelWidth) / 2) + "px");
|
2010-04-09 03:48:50 +02:00
|
|
|
}
|
|
|
|
|
2010-04-13 01:48:48 +02:00
|
|
|
function resizeTabs() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var totalHeight = ui.leftPanelDiv.height();
|
|
|
|
var headerHeight = ui.leftPanelTabs.find(".ui-tabs-nav").outerHeight(true);
|
|
|
|
|
|
|
|
var visibleTabPanels = ui.leftPanelTabs.find(".ui-tabs-panel:not(.ui-tabs-hide)");
|
|
|
|
var paddings = visibleTabPanels.outerHeight(true) - visibleTabPanels.height();
|
|
|
|
|
|
|
|
var allTabPanels = ui.leftPanelTabs.find(".ui-tabs-panel");
|
|
|
|
allTabPanels.height(totalHeight - headerHeight - paddings - 1);
|
2010-04-13 01:48:48 +02:00
|
|
|
}
|
|
|
|
|
2010-04-09 03:48:50 +02:00
|
|
|
function resizeAll() {
|
2011-08-04 22:37:14 +02:00
|
|
|
resize();
|
|
|
|
resizeTabs();
|
|
|
|
ui.extensionBar.resize();
|
|
|
|
ui.browsingEngine.resize();
|
|
|
|
ui.processPanel.resize();
|
|
|
|
ui.historyPanel.resize();
|
|
|
|
ui.dataTableView.resize();
|
2010-01-25 23:51:25 +01:00
|
|
|
}
|
2010-01-26 06:17:14 +01:00
|
|
|
|
2010-02-27 01:16:44 +01:00
|
|
|
function initializeUI(uiState) {
|
2011-08-04 22:37:14 +02:00
|
|
|
$("#loading-message").hide();
|
|
|
|
$("#notification-container").hide();
|
|
|
|
$("#project-title").show();
|
|
|
|
$("#project-controls").show();
|
|
|
|
$("#body").show();
|
2013-07-11 15:01:45 +02:00
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
$("#or-proj-open").text($.i18n('core-project/open')+"...");
|
|
|
|
$("#project-permalink-button").text($.i18n('core-project/permalink'));
|
|
|
|
$("#project-name-button").attr("title",$.i18n('core-project/proj-name'));
|
|
|
|
$("#or-proj-export").text($.i18n('core-project/export'));
|
|
|
|
$("#or-proj-help").text($.i18n('core-project/help'));
|
|
|
|
$("#or-proj-starting").text($.i18n('core-project/starting')+"...");
|
|
|
|
$("#or-proj-facFil").text($.i18n('core-project/facet-filter'));
|
|
|
|
$("#or-proj-undoRedo").text($.i18n('core-project/undo-redo'));
|
|
|
|
$("#or-proj-ext").text($.i18n('core-project/extensions')+":");
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
$('#project-name-button').click(Refine._renameProject);
|
|
|
|
$('#project-permalink-button').mouseenter(function() {
|
|
|
|
this.href = Refine.getPermanentLink();
|
|
|
|
});
|
|
|
|
|
|
|
|
Refine.setTitle();
|
|
|
|
|
|
|
|
ui = DOM.bind($("#body"));
|
|
|
|
|
|
|
|
ui.extensionBar = new ExtensionBar(ui.extensionBarDiv); // construct the menu first so we can resize everything else
|
|
|
|
ui.exporterManager = new ExporterManager($("#export-button"));
|
|
|
|
|
2020-08-17 14:49:56 +02:00
|
|
|
ui.leftPanelTabs.tabs();
|
2011-08-04 22:37:14 +02:00
|
|
|
resize();
|
|
|
|
resizeTabs();
|
|
|
|
|
2020-05-30 13:01:26 +02:00
|
|
|
$('<a>').attr("id", "hide-left-panel-button")
|
|
|
|
.addClass("visibility-panel-button")
|
|
|
|
.click(function() { Refine._showHideLeftPanel(); })
|
|
|
|
.prependTo(ui.leftPanelTabs);
|
|
|
|
|
|
|
|
$('<a>').attr("id", "show-left-panel-button")
|
|
|
|
.addClass("visibility-panel-button")
|
|
|
|
.click(function() { Refine._showHideLeftPanel(); })
|
|
|
|
.prependTo(ui.toolPanelDiv);
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
ui.summaryBar = new SummaryBar(ui.summaryBarDiv);
|
|
|
|
ui.browsingEngine = new BrowsingEngine(ui.facetPanelDiv, uiState.facets || []);
|
|
|
|
ui.processPanel = new ProcessPanel(ui.processPanelDiv);
|
|
|
|
ui.historyPanel = new HistoryPanel(ui.historyPanelDiv, ui.historyTabHeader);
|
|
|
|
ui.dataTableView = new DataTableView(ui.viewPanelDiv);
|
|
|
|
|
2017-09-20 11:08:03 +02:00
|
|
|
ui.leftPanelTabs.bind('tabsactivate', function(event, tabs) {
|
|
|
|
tabs.newPanel.resize();
|
2011-08-04 22:37:14 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$(window).bind("resize", resizeAll);
|
|
|
|
|
|
|
|
if (uiState.facets) {
|
|
|
|
Refine.update({ engineChanged: true });
|
|
|
|
}
|
2010-03-22 22:48:36 +01:00
|
|
|
}
|
|
|
|
|
2020-05-30 13:01:26 +02:00
|
|
|
Refine._showHideLeftPanel = function() {
|
|
|
|
$('div#body').toggleClass("hide-left-panel");
|
|
|
|
resizeAll();
|
|
|
|
};
|
|
|
|
|
2021-03-13 11:01:20 +01:00
|
|
|
Refine.showLeftPanel = function() {
|
|
|
|
$('div#body').removeClass("hide-left-panel");
|
2021-03-15 09:00:50 +01:00
|
|
|
if(ui.browsingEngine == undefined || ui.browsingEngine.resize == undefined) return;
|
2021-03-13 11:01:20 +01:00
|
|
|
resizeAll();
|
|
|
|
};
|
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.setTitle = function(status) {
|
2012-10-19 01:40:31 +02:00
|
|
|
var title = theProject.metadata.name + " - OpenRefine";
|
2011-08-04 22:37:14 +02:00
|
|
|
if (status) {
|
|
|
|
title = status + " - " + title;
|
|
|
|
}
|
|
|
|
document.title = title;
|
|
|
|
|
|
|
|
$("#project-name-button").text(theProject.metadata.name);
|
2010-05-01 00:49:59 +02:00
|
|
|
};
|
|
|
|
|
2012-01-29 22:16:13 +01:00
|
|
|
Refine.reinitializeProjectData = function(f, fError) {
|
|
|
|
$.getJSON(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/get-project-metadata?" + $.param({ project: theProject.id }), null,
|
2011-08-04 22:37:14 +02:00
|
|
|
function(data) {
|
2017-10-27 12:47:59 +02:00
|
|
|
if (data.status == "error") {
|
2012-01-29 22:16:13 +01:00
|
|
|
alert(data.message);
|
|
|
|
if (fError) {
|
|
|
|
fError();
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
2012-01-29 22:16:13 +01:00
|
|
|
} else {
|
|
|
|
theProject.metadata = data;
|
|
|
|
$.getJSON(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/get-models?" + $.param({ project: theProject.id }), null,
|
2012-01-29 22:16:13 +01:00
|
|
|
function(data) {
|
2020-06-18 10:35:37 +02:00
|
|
|
if (data.status == "error") {
|
|
|
|
alert(data.message);
|
|
|
|
if (fError) {
|
|
|
|
fError();
|
2012-01-29 22:16:13 +01:00
|
|
|
}
|
2020-06-18 10:35:37 +02:00
|
|
|
} else {
|
|
|
|
for (var n in data) {
|
|
|
|
if (data.hasOwnProperty(n)) {
|
|
|
|
theProject[n] = data[n];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$.post(
|
|
|
|
"command/core/get-all-preferences", null,
|
|
|
|
function(preferences) {
|
|
|
|
if (preferences.status == "error") {
|
|
|
|
alert(preferences.message);
|
|
|
|
if (fError) {
|
|
|
|
fError();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (preferences != null) {
|
|
|
|
thePreferences = preferences;
|
|
|
|
}
|
|
|
|
f();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'json'
|
|
|
|
);
|
2012-01-29 22:16:13 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
'json'
|
|
|
|
);
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
},
|
2012-01-29 22:16:13 +01:00
|
|
|
'json'
|
2011-08-04 22:37:14 +02:00
|
|
|
);
|
2010-04-08 21:52:23 +02:00
|
|
|
};
|
2010-02-22 21:25:45 +01:00
|
|
|
|
2020-06-18 10:35:37 +02:00
|
|
|
Refine.getPreference = function(key, defaultValue) {
|
|
|
|
if(!thePreferences.hasOwnProperty(key)) { return defaultValue; }
|
|
|
|
|
|
|
|
return thePreferences[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
Refine.setPreference = function(key, newValue) {
|
|
|
|
thePreferences[key] = newValue;
|
|
|
|
|
|
|
|
Refine.wrapCSRF(function(token) {
|
|
|
|
$.ajax({
|
|
|
|
async: false,
|
|
|
|
type: "POST",
|
|
|
|
url: "command/core/set-preference?" + $.param({ name: key }),
|
|
|
|
data: {
|
|
|
|
"value" : JSON.stringify(newValue),
|
|
|
|
csrf_token: token
|
|
|
|
},
|
|
|
|
success: function(data) { },
|
|
|
|
dataType: "json"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-10-02 04:06:01 +02:00
|
|
|
Refine._renameProject = function() {
|
2018-11-21 18:30:00 +01:00
|
|
|
var name = window.prompt($.i18n('core-index/new-proj-name'), theProject.metadata.name);
|
2011-10-08 01:44:11 +02:00
|
|
|
if (name === null) {
|
2011-08-04 22:37:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2010-10-02 04:06:01 +02:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
name = $.trim(name);
|
2011-10-08 01:44:11 +02:00
|
|
|
if (theProject.metadata.name == name || name.length === 0) {
|
2011-08-04 22:37:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2010-10-02 04:06:01 +02:00
|
|
|
|
2019-10-14 15:04:38 +02:00
|
|
|
Refine.postCSRF(
|
|
|
|
"command/core/rename-project",
|
|
|
|
{ "project" : theProject.id, "name" : name },
|
|
|
|
function (data) {
|
2017-10-27 13:22:01 +02:00
|
|
|
if (data && typeof data.code != "undefined" && data.code == "ok") {
|
2011-08-04 22:37:14 +02:00
|
|
|
theProject.metadata.name = name;
|
|
|
|
Refine.setTitle();
|
|
|
|
} else {
|
2018-11-21 18:30:00 +01:00
|
|
|
alert($.i18n('core-index/error-rename')+" " + data.message);
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
2019-10-14 15:04:38 +02:00
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
2010-10-02 04:06:01 +02:00
|
|
|
};
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
/*
|
|
|
|
* Utility state functions
|
|
|
|
*/
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2018-03-30 12:40:01 +02:00
|
|
|
Refine.customUpdateCallbacks = [];
|
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.createUpdateFunction = function(options, onFinallyDone) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var functions = [];
|
|
|
|
var pushFunction = function(f) {
|
|
|
|
var index = functions.length;
|
|
|
|
functions.push(function() {
|
|
|
|
f(functions[index + 1]);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
pushFunction(function(onDone) {
|
|
|
|
ui.historyPanel.update(onDone);
|
|
|
|
});
|
|
|
|
if (options.everythingChanged || options.modelsChanged || options.columnStatsChanged) {
|
|
|
|
pushFunction(Refine.reinitializeProjectData);
|
|
|
|
}
|
|
|
|
if (options.everythingChanged || options.modelsChanged || options.rowsChanged || options.rowMetadataChanged || options.cellsChanged || options.engineChanged) {
|
2010-02-26 22:56:41 +01:00
|
|
|
pushFunction(function(onDone) {
|
2011-08-04 22:37:14 +02:00
|
|
|
ui.dataTableView.update(onDone);
|
2010-02-26 22:56:41 +01:00
|
|
|
});
|
2011-08-04 22:37:14 +02:00
|
|
|
pushFunction(function(onDone) {
|
|
|
|
ui.browsingEngine.update(onDone);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-30 12:40:01 +02:00
|
|
|
// run the callbacks registered by extensions, passing them
|
|
|
|
// the options
|
|
|
|
pushFunction(function(onDone) {
|
|
|
|
for(var i = 0; i != Refine.customUpdateCallbacks.length; i++) {
|
|
|
|
Refine.customUpdateCallbacks[i](options);
|
|
|
|
}
|
|
|
|
onDone();
|
|
|
|
});
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
functions.push(onFinallyDone || function() {});
|
|
|
|
|
|
|
|
return functions[0];
|
2010-02-26 22:56:41 +01:00
|
|
|
};
|
|
|
|
|
2018-03-30 12:40:01 +02:00
|
|
|
/*
|
|
|
|
* Registers a callback function to be called after each update.
|
|
|
|
* This is provided for extensions which need to run some code when
|
|
|
|
* the project is updated. This was introduced for the Wikidata
|
|
|
|
* extension as a means to avoid monkey-patching Refine's core
|
|
|
|
* methods (which was the solution adopted for GOKb, as they had
|
|
|
|
* no way to change Refine's code directly).
|
|
|
|
*
|
|
|
|
* The function will be called with an "options" object as above
|
|
|
|
* describing which change has happened, so that the code can run
|
|
|
|
* fine-grained updates.
|
|
|
|
*/
|
|
|
|
Refine.registerUpdateFunction = function(callback) {
|
|
|
|
Refine.customUpdateCallbacks.push(callback);
|
|
|
|
}
|
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.update = function(options, onFinallyDone) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var done = false;
|
|
|
|
var dismissBusy = null;
|
|
|
|
|
|
|
|
Refine.setAjaxInProgress();
|
|
|
|
|
|
|
|
Refine.createUpdateFunction(options, function() {
|
|
|
|
Refine.clearAjaxInProgress();
|
|
|
|
|
|
|
|
done = true;
|
|
|
|
if (dismissBusy) {
|
|
|
|
dismissBusy();
|
|
|
|
}
|
|
|
|
if (onFinallyDone) {
|
|
|
|
onFinallyDone();
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
window.setTimeout(function() {
|
|
|
|
if (!done) {
|
|
|
|
dismissBusy = DialogSystem.showBusy();
|
|
|
|
}
|
|
|
|
}, 500);
|
2010-02-26 22:56:41 +01:00
|
|
|
};
|
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.postCoreProcess = function(command, params, body, updateOptions, callbacks) {
|
2011-08-04 22:37:14 +02:00
|
|
|
Refine.postProcess("core", command, params, body, updateOptions, callbacks);
|
2010-08-22 08:16:13 +02:00
|
|
|
};
|
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.postProcess = function(moduleName, command, params, body, updateOptions, callbacks) {
|
2011-08-04 22:37:14 +02:00
|
|
|
updateOptions = updateOptions || {};
|
|
|
|
callbacks = callbacks || {};
|
|
|
|
|
|
|
|
params = params || {};
|
|
|
|
params.project = theProject.id;
|
|
|
|
|
|
|
|
body = body || {};
|
|
|
|
if (!("includeEngine" in updateOptions) || updateOptions.includeEngine) {
|
|
|
|
body.engine = JSON.stringify(
|
|
|
|
"engineConfig" in updateOptions ?
|
|
|
|
updateOptions.engineConfig :
|
|
|
|
ui.browsingEngine.getJSON()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
var done = false;
|
|
|
|
var dismissBusy = null;
|
|
|
|
|
|
|
|
function onDone(o) {
|
|
|
|
done = true;
|
|
|
|
if (dismissBusy) {
|
|
|
|
dismissBusy();
|
2010-04-09 00:16:12 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
Refine.clearAjaxInProgress();
|
|
|
|
|
|
|
|
if (o.code == "error") {
|
|
|
|
if ("onError" in callbacks) {
|
|
|
|
try {
|
|
|
|
callbacks.onError(o);
|
|
|
|
} catch (e) {
|
|
|
|
Refine.reportException(e);
|
2010-02-26 22:56:41 +01:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
} else {
|
|
|
|
alert(o.message);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ("onDone" in callbacks) {
|
|
|
|
try {
|
|
|
|
callbacks.onDone(o);
|
|
|
|
} catch (e) {
|
|
|
|
Refine.reportException(e);
|
2010-02-26 22:56:41 +01:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (o.code == "ok") {
|
|
|
|
Refine.update(updateOptions, callbacks.onFinallyDone);
|
|
|
|
|
|
|
|
if ("historyEntry" in o) {
|
|
|
|
ui.processPanel.showUndo(o.historyEntry);
|
|
|
|
}
|
|
|
|
} else if (o.code == "pending") {
|
|
|
|
if ("onPending" in callbacks) {
|
|
|
|
try {
|
|
|
|
callbacks.onPending(o);
|
|
|
|
} catch (e) {
|
|
|
|
Refine.reportException(e);
|
|
|
|
}
|
2010-02-26 22:56:41 +01:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
ui.processPanel.update(updateOptions, callbacks.onFinallyDone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Refine.setAjaxInProgress();
|
|
|
|
|
2019-10-11 14:53:43 +02:00
|
|
|
Refine.postCSRF(
|
|
|
|
"command/" + moduleName + "/" + command + "?" + $.param(params),
|
|
|
|
body,
|
|
|
|
onDone,
|
|
|
|
"json"
|
2011-08-04 22:37:14 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
window.setTimeout(function() {
|
|
|
|
if (!done) {
|
|
|
|
dismissBusy = DialogSystem.showBusy();
|
|
|
|
}
|
|
|
|
}, 500);
|
2010-02-26 22:56:41 +01:00
|
|
|
};
|
|
|
|
|
2019-10-11 13:24:44 +02:00
|
|
|
// Requests a CSRF token and calls the supplied callback
|
|
|
|
// with the token
|
|
|
|
Refine.wrapCSRF = function(onCSRF) {
|
|
|
|
$.get(
|
|
|
|
"command/core/get-csrf-token",
|
|
|
|
{},
|
|
|
|
function(response) {
|
|
|
|
onCSRF(response['token']);
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-10-11 14:53:43 +02:00
|
|
|
// Performs a POST request where an additional CSRF token
|
|
|
|
// is supplied in the POST data. The arguments match those
|
|
|
|
// of $.post().
|
|
|
|
Refine.postCSRF = function(url, data, success, dataType) {
|
|
|
|
Refine.wrapCSRF(function(token) {
|
|
|
|
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-11 16:30:54 +02:00
|
|
|
$.post(url, fullData, success, dataType);
|
2019-10-11 14:53:43 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.setAjaxInProgress = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
$(document.body).attr("ajax_in_progress", "true");
|
2010-04-07 23:31:50 +02:00
|
|
|
};
|
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.clearAjaxInProgress = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
$(document.body).attr("ajax_in_progress", "false");
|
2010-04-07 23:31:50 +02:00
|
|
|
};
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
/*
|
|
|
|
* Utility model functions
|
|
|
|
*/
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.cellIndexToColumn = function(cellIndex) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var columns = theProject.columnModel.columns;
|
|
|
|
for (var i = 0; i < columns.length; i++) {
|
|
|
|
var column = columns[i];
|
|
|
|
if (column.cellIndex == cellIndex) {
|
|
|
|
return column;
|
2010-04-24 03:19:13 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
return null;
|
2010-04-24 03:19:13 +02:00
|
|
|
};
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.columnNameToColumn = function(columnName) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var columns = theProject.columnModel.columns;
|
|
|
|
for (var i = 0; i < columns.length; i++) {
|
|
|
|
var column = columns[i];
|
|
|
|
if (column.name == columnName) {
|
|
|
|
return column;
|
2010-02-22 21:25:45 +01:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
return null;
|
2010-02-26 22:56:41 +01:00
|
|
|
};
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.columnNameToColumnIndex = function(columnName) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var columns = theProject.columnModel.columns;
|
|
|
|
for (var i = 0; i < columns.length; i++) {
|
|
|
|
var column = columns[i];
|
|
|
|
if (column.name == columnName) {
|
|
|
|
return i;
|
2010-08-07 03:24:48 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
return -1;
|
2010-08-07 03:24:48 +02:00
|
|
|
};
|
2010-02-26 22:56:41 +01:00
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.fetchRows = function(start, limit, onDone, sorting) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var body = {
|
|
|
|
engine: JSON.stringify(ui.browsingEngine.getJSON())
|
|
|
|
};
|
|
|
|
if (sorting) {
|
2011-10-08 01:44:11 +02:00
|
|
|
body.sorting = JSON.stringify(sorting);
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$.post(
|
2017-10-27 11:53:27 +02:00
|
|
|
"command/core/get-rows?" + $.param({ project: theProject.id, start: start, limit: limit }),
|
2011-08-04 22:37:14 +02:00
|
|
|
body,
|
|
|
|
function(data) {
|
2017-10-27 13:22:01 +02:00
|
|
|
if(data.code === "error") {
|
2017-10-27 11:53:27 +02:00
|
|
|
data = theProject.rowModel;
|
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
theProject.rowModel = data;
|
|
|
|
|
|
|
|
// Un-pool objects
|
|
|
|
for (var r = 0; r < data.rows.length; r++) {
|
|
|
|
var row = data.rows[r];
|
|
|
|
for (var c = 0; c < row.cells.length; c++) {
|
|
|
|
var cell = row.cells[c];
|
|
|
|
if ((cell) && ("r" in cell)) {
|
|
|
|
cell.r = data.pool.recons[cell.r];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (onDone) {
|
|
|
|
onDone();
|
|
|
|
}
|
|
|
|
},
|
2017-10-27 11:53:27 +02:00
|
|
|
"json"
|
2011-08-04 22:37:14 +02:00
|
|
|
);
|
2010-02-26 22:56:41 +01:00
|
|
|
};
|
2010-02-27 01:16:44 +01:00
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.getPermanentLink = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var params = [
|
2015-10-16 21:21:21 +02:00
|
|
|
"project=" + encodeURIComponent(theProject.id),
|
|
|
|
"ui=" + encodeURIComponent(JSON.stringify({
|
2011-08-04 22:37:14 +02:00
|
|
|
facets: ui.browsingEngine.getFacetUIStates()
|
|
|
|
}))
|
|
|
|
];
|
|
|
|
return "project?" + params.join("&");
|
2010-02-27 01:16:44 +01:00
|
|
|
};
|
2010-04-09 03:48:50 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Loader
|
|
|
|
*/
|
|
|
|
|
|
|
|
function onLoad() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var params = URL.getParameters();
|
|
|
|
if ("project" in params) {
|
|
|
|
var uiState = {};
|
|
|
|
if ("ui" in params) {
|
|
|
|
try {
|
2015-10-16 21:21:21 +02:00
|
|
|
uiState = JSON.parse(decodeURIComponent(params.ui));
|
2011-08-04 22:37:14 +02:00
|
|
|
} catch (e) {
|
|
|
|
}
|
2010-04-09 03:48:50 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2012-01-29 22:16:13 +01:00
|
|
|
Refine.reinitializeProjectData(
|
|
|
|
function() {
|
|
|
|
initializeUI(uiState);
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
$("#loading-message").hide();
|
|
|
|
}
|
|
|
|
);
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
2010-04-09 03:48:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$(onLoad);
|