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-08-09 03:13:57 +02:00
|
|
|
function DataTableColumnHeaderUI(dataTableView, column, columnIndex, td) {
|
2011-08-04 22:37:14 +02:00
|
|
|
this._dataTableView = dataTableView;
|
|
|
|
this._column = column;
|
|
|
|
this._columnIndex = columnIndex;
|
|
|
|
this._td = td;
|
|
|
|
|
|
|
|
this._render();
|
2010-08-09 03:13:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DataTableColumnHeaderUI._extenders = [];
|
|
|
|
|
2010-10-18 03:53:23 +02:00
|
|
|
/*
|
2011-08-04 22:37:14 +02:00
|
|
|
To extend, call
|
|
|
|
|
|
|
|
DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
|
|
|
|
...
|
|
|
|
MenuSystem.appendTo(menu, path, newItems);
|
|
|
|
});
|
|
|
|
*/
|
2010-08-09 03:13:57 +02:00
|
|
|
DataTableColumnHeaderUI.extendMenu = function(extender) {
|
2011-08-04 22:37:14 +02:00
|
|
|
DataTableColumnHeaderUI._extenders.push(extender);
|
2010-08-09 03:13:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
DataTableColumnHeaderUI.prototype.getColumn = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
return this._column;
|
2010-08-09 03:13:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
DataTableColumnHeaderUI.prototype._render = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
var td = $(this._td);
|
|
|
|
|
|
|
|
td.html(DOM.loadHTML("core", "scripts/views/data-table/column-header.html"));
|
|
|
|
var elmts = DOM.bind(td);
|
|
|
|
|
|
|
|
elmts.nameContainer.text(this._column.name);
|
|
|
|
elmts.dropdownMenu.click(function() {
|
|
|
|
self._createMenuForColumnHeader(this);
|
|
|
|
});
|
|
|
|
|
|
|
|
if ("reconStats" in this._column) {
|
|
|
|
var stats = this._column.reconStats;
|
|
|
|
if (stats.nonBlanks > 0) {
|
|
|
|
var newPercent = Math.ceil(100 * stats.newTopics / stats.nonBlanks);
|
|
|
|
var matchPercent = Math.ceil(100 * stats.matchedTopics / stats.nonBlanks);
|
|
|
|
var unreconciledPercent = Math.ceil(100 * (stats.nonBlanks - stats.matchedTopics - stats.newTopics) / stats.nonBlanks);
|
2018-11-21 16:24:57 +01:00
|
|
|
var title = matchPercent + "% "+$.i18n._('core-views/matched')+", " + newPercent + "% "+$.i18n._('core-views/new')+", " + unreconciledPercent + "% "+$.i18n._('core-views/to-be-recon');
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
var whole = $('<div>')
|
|
|
|
.addClass("column-header-recon-stats-bar")
|
|
|
|
.attr("title", title)
|
|
|
|
.appendTo(elmts.reconStatsContainer.show());
|
|
|
|
|
|
|
|
$('<div>')
|
|
|
|
.addClass("column-header-recon-stats-blanks")
|
|
|
|
.width(Math.round((stats.newTopics + stats.matchedTopics) * 100 / stats.nonBlanks) + "%")
|
|
|
|
.appendTo(whole);
|
|
|
|
|
|
|
|
$('<div>')
|
|
|
|
.addClass("column-header-recon-stats-matched")
|
|
|
|
.width(Math.round(stats.matchedTopics * 100 / stats.nonBlanks) + "%")
|
|
|
|
.appendTo(whole);
|
2010-08-09 03:13:57 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
2010-08-09 03:13:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
DataTableColumnHeaderUI.prototype._createMenuForColumnHeader = function(elmt) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
var menu = [
|
|
|
|
{
|
|
|
|
id: "core/facet",
|
2018-11-21 16:24:57 +01:00
|
|
|
label: $.i18n._('core-views/facet'),
|
2011-08-04 22:37:14 +02:00
|
|
|
width: "170px",
|
|
|
|
submenu: []
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
id: "core/edit-cells",
|
2018-11-21 16:24:57 +01:00
|
|
|
label: $.i18n._('core-views/edit-cells'),
|
2011-08-04 22:37:14 +02:00
|
|
|
width: "170px",
|
|
|
|
submenu: []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "core/edit-column",
|
2018-11-21 16:24:57 +01:00
|
|
|
label: $.i18n._('core-views/edit-column'),
|
2011-08-04 22:37:14 +02:00
|
|
|
submenu: []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "core/transpose",
|
2018-11-21 16:24:57 +01:00
|
|
|
label: $.i18n._('core-views/transpose'),
|
2011-08-04 22:37:14 +02:00
|
|
|
submenu: []
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
(
|
2011-10-08 01:44:11 +02:00
|
|
|
this._dataTableView._getSortingCriterionForColumn(this._column.name) === null ?
|
2010-08-09 03:13:57 +02:00
|
|
|
{
|
2011-08-04 22:37:14 +02:00
|
|
|
id: "core/sort",
|
2018-11-21 16:24:57 +01:00
|
|
|
"label": $.i18n._('core-views/sort')+"...",
|
2011-08-04 22:37:14 +02:00
|
|
|
"click": function() {
|
2011-10-08 01:44:11 +02:00
|
|
|
self._showSortingCriterion(null, self._dataTableView._getSortingCriteriaCount() > 0);
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
} :
|
2010-08-09 03:13:57 +02:00
|
|
|
{
|
2011-08-04 22:37:14 +02:00
|
|
|
id: "core/sort",
|
2018-11-21 16:24:57 +01:00
|
|
|
label: $.i18n._('core-views/sort'),
|
2011-08-04 22:37:14 +02:00
|
|
|
submenu: this.createSortingMenu()
|
|
|
|
}
|
|
|
|
),
|
|
|
|
{
|
|
|
|
id: "core/view",
|
2018-11-21 16:24:57 +01:00
|
|
|
label: $.i18n._('core-views/view'),
|
|
|
|
tooltip: $.i18n._('core-views/collapse-expand'),
|
2011-08-04 22:37:14 +02:00
|
|
|
submenu: [
|
2010-08-09 03:13:57 +02:00
|
|
|
{
|
2018-11-21 16:24:57 +01:00
|
|
|
label: $.i18n._('core-views/collapse-this'),
|
2011-08-04 22:37:14 +02:00
|
|
|
click: function() {
|
|
|
|
self._dataTableView._collapsedColumnNames[self._column.name] = true;
|
|
|
|
self._dataTableView.render();
|
|
|
|
}
|
2010-08-09 03:13:57 +02:00
|
|
|
},
|
|
|
|
{
|
2018-11-21 16:24:57 +01:00
|
|
|
label: $.i18n._('core-views/collapse-other'),
|
2011-08-04 22:37:14 +02:00
|
|
|
click: function() {
|
|
|
|
var collapsedColumnNames = {};
|
|
|
|
for (var i = 0; i < theProject.columnModel.columns.length; i++) {
|
|
|
|
if (i != self._columnIndex) {
|
|
|
|
collapsedColumnNames[theProject.columnModel.columns[i].name] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self._dataTableView._collapsedColumnNames = collapsedColumnNames;
|
|
|
|
self._dataTableView.render();
|
|
|
|
}
|
2010-08-09 03:13:57 +02:00
|
|
|
},
|
|
|
|
{
|
2018-11-21 16:24:57 +01:00
|
|
|
label: $.i18n._('core-views/collapse-left'),
|
2011-08-04 22:37:14 +02:00
|
|
|
click: function() {
|
|
|
|
for (var i = 0; i < self._columnIndex; i++) {
|
|
|
|
self._dataTableView._collapsedColumnNames[theProject.columnModel.columns[i].name] = true;
|
|
|
|
}
|
|
|
|
self._dataTableView.render();
|
|
|
|
}
|
2010-08-09 03:13:57 +02:00
|
|
|
},
|
|
|
|
{
|
2018-11-21 16:24:57 +01:00
|
|
|
label: $.i18n._('core-views/collapse-right'),
|
2011-08-04 22:37:14 +02:00
|
|
|
click: function() {
|
|
|
|
for (var i = self._columnIndex + 1; i < theProject.columnModel.columns.length; i++) {
|
|
|
|
self._dataTableView._collapsedColumnNames[theProject.columnModel.columns[i].name] = true;
|
|
|
|
}
|
|
|
|
self._dataTableView.render();
|
|
|
|
}
|
2010-08-09 03:13:57 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
id: "core/reconcile",
|
2018-11-21 16:24:57 +01:00
|
|
|
label: $.i18n._('core-views/reconcile'),
|
|
|
|
tooltip: $.i18n._('core-views/reconcile-tooltip'),
|
2011-08-04 22:37:14 +02:00
|
|
|
width: "170px",
|
|
|
|
submenu: []
|
2010-08-09 03:13:57 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
for (var i = 0; i < DataTableColumnHeaderUI._extenders.length; i++) {
|
|
|
|
DataTableColumnHeaderUI._extenders[i].call(null, this._column, this, menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
MenuSystem.createAndShowStandardMenu(menu, elmt, { width: "120px", horizontal: false });
|
2010-08-09 03:13:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
DataTableColumnHeaderUI.prototype.createSortingMenu = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
var criterion = this._dataTableView._getSortingCriterionForColumn(this._column.name);
|
|
|
|
var criteriaCount = this._dataTableView._getSortingCriteriaCount();
|
2011-10-08 01:44:11 +02:00
|
|
|
var hasOtherCriteria = (criterion === null) ? (criteriaCount > 0) : criteriaCount > 1;
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
var items = [
|
|
|
|
{
|
2018-11-21 16:24:57 +01:00
|
|
|
"label": $.i18n._('core-views/sort')+"...",
|
2011-08-04 22:37:14 +02:00
|
|
|
"click": function() {
|
2011-10-08 01:44:11 +02:00
|
|
|
self._showSortingCriterion(criterion, hasOtherCriteria);
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
2010-08-09 03:13:57 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
];
|
|
|
|
|
2011-10-08 01:44:11 +02:00
|
|
|
if (criterion !== null) {
|
2011-08-04 22:37:14 +02:00
|
|
|
items.push({
|
2018-11-21 16:24:57 +01:00
|
|
|
"label": $.i18n._('core-views/reverse'),
|
2011-08-04 22:37:14 +02:00
|
|
|
"click": function() {
|
|
|
|
criterion.reverse = !criterion.reverse;
|
|
|
|
self._dataTableView._addSortingCriterion(criterion);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
items.push({
|
2018-11-21 16:24:57 +01:00
|
|
|
"label": $.i18n._('core-views/remove-sort'),
|
2011-08-04 22:37:14 +02:00
|
|
|
"click": function() {
|
|
|
|
self._dataTableView._removeSortingCriterionOfColumn(criterion.column);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return items;
|
2010-08-09 03:13:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
DataTableColumnHeaderUI.prototype._showSortingCriterion = function(criterion, hasOtherCriteria) {
|
2011-08-04 22:37:14 +02:00
|
|
|
criterion = criterion || {
|
|
|
|
column: this._column.name,
|
|
|
|
valueType: "string",
|
|
|
|
caseSensitive: false,
|
|
|
|
errorPosition: 1,
|
|
|
|
blankPosition: 2
|
|
|
|
};
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
var frame = $(DOM.loadHTML("core", "scripts/views/data-table/sorting-criterion-dialog.html"));
|
|
|
|
var elmts = DOM.bind(frame);
|
|
|
|
|
2018-11-21 16:24:57 +01:00
|
|
|
elmts.dialogHeader.text($.i18n._('core-views/sort-by')+' ' + this._column.name);
|
2013-07-09 15:57:25 +02:00
|
|
|
|
2018-11-21 16:24:57 +01:00
|
|
|
elmts.or_views_sortAs.text($.i18n._('core-views/sort-cell'));
|
|
|
|
elmts.or_views_positionBlank.text($.i18n._('core-views/pos-blank'));
|
2013-07-09 15:57:25 +02:00
|
|
|
|
2018-11-21 16:24:57 +01:00
|
|
|
elmts.or_views_text.text($.i18n._('core-views/text'));
|
|
|
|
elmts.or_views_caseSens.text($.i18n._('core-views/case-sensitive'));
|
|
|
|
elmts.or_views_numbers.text($.i18n._('core-views/numbers'));
|
|
|
|
elmts.or_views_dates.text($.i18n._('core-views/dates'));
|
|
|
|
elmts.or_views_booleans.text($.i18n._('core-views/booleans'));
|
|
|
|
elmts.or_views_dragDrop.text($.i18n._('core-views/drag-drop'));
|
|
|
|
elmts.directionForwardLabel.text($.i18n._('core-views/forward'));
|
|
|
|
elmts.directionReverseLabel.text($.i18n._('core-views/reverse'));
|
|
|
|
elmts.or_views_sortByCol.text($.i18n._('core-views/sort-by-col'));
|
|
|
|
elmts.okButton.html($.i18n._('core-buttons/ok'));
|
|
|
|
elmts.cancelButton.text($.i18n._('core-buttons/cancel'));
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
elmts.valueTypeOptions
|
|
|
|
.find("input[type='radio'][value='" + criterion.valueType + "']")
|
|
|
|
.attr("checked", "checked");
|
|
|
|
|
|
|
|
var setValueType = function(valueType) {
|
|
|
|
var forward = elmts.directionForwardLabel;
|
|
|
|
var reverse = elmts.directionReverseLabel;
|
|
|
|
if (valueType == "string") {
|
|
|
|
forward.html("a - z");
|
|
|
|
reverse.html("z - a");
|
|
|
|
} else if (valueType == "number") {
|
2018-11-21 16:24:57 +01:00
|
|
|
forward.html($.i18n._('core-views/smallest-first'));
|
|
|
|
reverse.html($.i18n._('core-views/largest-first'));
|
2011-08-04 22:37:14 +02:00
|
|
|
} else if (valueType == "date") {
|
2018-11-21 16:24:57 +01:00
|
|
|
forward.html($.i18n._('core-views/earliest-first'));
|
|
|
|
reverse.html($.i18n._('core-views/latest-first'));
|
2011-08-04 22:37:14 +02:00
|
|
|
} else if (valueType == "boolean") {
|
2018-11-21 16:24:57 +01:00
|
|
|
forward.html($.i18n._('core-views/false-true'));
|
|
|
|
reverse.html($.i18n._('core-views/true-false'));
|
2010-08-09 03:13:57 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
};
|
|
|
|
elmts.valueTypeOptions
|
|
|
|
.find("input[type='radio']")
|
|
|
|
.change(function() {
|
|
|
|
setValueType(this.value);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (criterion.valueType == "string" && criterion.caseSensitive) {
|
|
|
|
elmts.caseSensitiveCheckbox.attr("checked", "checked");
|
|
|
|
}
|
2010-08-09 03:13:57 +02:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
elmts.directionOptions
|
|
|
|
.find("input[type='radio'][value='" + (criterion.reverse ? "reverse" : "forward") + "']")
|
|
|
|
.attr("checked", "checked");
|
|
|
|
|
|
|
|
if (hasOtherCriteria) {
|
|
|
|
elmts.sortAloneContainer.show();
|
|
|
|
}
|
|
|
|
|
2018-11-21 16:24:57 +01:00
|
|
|
var validValuesHtml = '<li kind="value">'+$.i18n._('core-views/valid-values')+'</li>';
|
|
|
|
var blankValuesHtml = '<li kind="blank">'+$.i18n._('core-views/blanks')+'</li>';
|
|
|
|
var errorValuesHtml = '<li kind="error">'+$.i18n._('core-views/errors')+'</li>';
|
2011-08-04 22:37:14 +02:00
|
|
|
var positionsHtml;
|
|
|
|
if (criterion.blankPosition < 0) {
|
|
|
|
if (criterion.errorPosition > 0) {
|
|
|
|
positionsHtml = [ blankValuesHtml, validValuesHtml, errorValuesHtml ];
|
|
|
|
} else if (criterion.errorPosition < criterion.blankPosition) {
|
|
|
|
positionsHtml = [ errorValuesHtml, blankValuesHtml, validValuesHtml ];
|
|
|
|
} else {
|
|
|
|
positionsHtml = [ blankValuesHtml, errorValuesHtml, validValuesHtml ];
|
2010-08-09 03:13:57 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
} else {
|
|
|
|
if (criterion.errorPosition < 0) {
|
|
|
|
positionsHtml = [ errorValuesHtml, validValuesHtml, blankValuesHtml ];
|
|
|
|
} else if (criterion.errorPosition < criterion.blankPosition) {
|
|
|
|
positionsHtml = [ validValuesHtml, errorValuesHtml, blankValuesHtml ];
|
2010-08-09 03:13:57 +02:00
|
|
|
} else {
|
2011-08-04 22:37:14 +02:00
|
|
|
positionsHtml = [ validValuesHtml, blankValuesHtml, errorValuesHtml ];
|
2010-08-09 03:13:57 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
elmts.blankErrorPositions.html(positionsHtml.join("")).sortable().disableSelection();
|
|
|
|
|
|
|
|
var level = DialogSystem.showDialog(frame);
|
2015-05-01 21:04:51 +02:00
|
|
|
var dismiss = function() { DialogSystem.dismissLevel(level - 1); };
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
setValueType(criterion.valueType);
|
|
|
|
|
|
|
|
elmts.cancelButton.click(dismiss);
|
|
|
|
elmts.okButton.click(function() {
|
|
|
|
var criterion2 = {
|
|
|
|
column: self._column.name,
|
|
|
|
valueType: elmts.valueTypeOptions.find("input[type='radio']:checked")[0].value,
|
|
|
|
reverse: elmts.directionOptions.find("input[type='radio']:checked")[0].value == "reverse"
|
|
|
|
};
|
|
|
|
|
|
|
|
var valuePosition, blankPosition, errorPosition;
|
|
|
|
elmts.blankErrorPositions.find("li").each(function(index, elmt) {
|
|
|
|
var kind = this.getAttribute("kind");
|
|
|
|
if (kind == "value") {
|
|
|
|
valuePosition = index;
|
|
|
|
} else if (kind == "blank") {
|
|
|
|
blankPosition = index;
|
|
|
|
} else if (kind == "error") {
|
|
|
|
errorPosition = index;
|
|
|
|
}
|
2010-08-09 03:13:57 +02:00
|
|
|
});
|
2011-08-04 22:37:14 +02:00
|
|
|
criterion2.blankPosition = blankPosition - valuePosition;
|
|
|
|
criterion2.errorPosition = errorPosition - valuePosition;
|
|
|
|
|
|
|
|
if (criterion2.valueType == "string") {
|
|
|
|
criterion2.caseSensitive = elmts.caseSensitiveCheckbox[0].checked;
|
|
|
|
}
|
|
|
|
|
|
|
|
self._dataTableView._addSortingCriterion(
|
|
|
|
criterion2, elmts.sortAloneContainer.find("input")[0].checked);
|
|
|
|
|
|
|
|
dismiss();
|
|
|
|
});
|
2015-04-21 15:07:32 +02:00
|
|
|
};
|