511 lines
21 KiB
JavaScript
511 lines
21 KiB
JavaScript
/// <reference path="../../components/datagrid.js" />
|
|
/// <reference path="selectChartSubType.js" />
|
|
/// <reference path="../../../../js/utility.js" />
|
|
/// <reference path="../chartTypeWizard.js" />
|
|
/// <reference path="subctrls/targetMappingHeader.js" />
|
|
/// <reference path="drilldownurl.js" />
|
|
/// <reference path="drilldownchart.js" />
|
|
|
|
if (typeof $drilldownCellSetupCtrl !== "function") {
|
|
$drilldownCellSetupCtrl = $wizardCtrl.extend({
|
|
// prototypes
|
|
text: GetLanguageByKey("LHBIS_FIC_CLIENT_WIZARD_CHARTWIZARDHELPER_A363", "Drilldown Cell Setup"),
|
|
name: "SetDrillDownCell",
|
|
chooseEnable: false,
|
|
jumpPass: false,
|
|
// new $drilldownCellSetupCtrl() executes
|
|
init: function () { }
|
|
});
|
|
|
|
(function () {
|
|
"use strict";
|
|
|
|
function loadNode(node, next, content) {
|
|
content = content || this.wizardCtrl.contentAreaCtrl;
|
|
if (node && node.ID === 'root') {
|
|
content.find('.content-drilldown').hide();
|
|
next();
|
|
} else {
|
|
content.find('.cell-text').val(node.Description);
|
|
content.find('.column-header').val(node.Header);
|
|
var ps = [];
|
|
ps.push(new Promise(function (resolve) {
|
|
node.drilldown_url.createContent(function (cnt) {
|
|
content.find('.drilldown-url-content').empty().append(cnt.find('#DrillDownUrlCtrl'));
|
|
resolve();
|
|
});
|
|
}));
|
|
ps.push(new Promise(function (resolve) {
|
|
node.drilldown_chart.createContent(function (cnt) {
|
|
content.find('.drilldown-chart-content').empty().append(cnt);
|
|
resolve();
|
|
});
|
|
}));
|
|
Promise.all(ps).then(function () {
|
|
content.find('.content-drilldown').show();
|
|
changeOption(content, node);
|
|
}).then(next);
|
|
}
|
|
}
|
|
|
|
function onTreeSelected(ele, next, content) {
|
|
var node = ele.data('val');
|
|
if (node == null) {
|
|
return;
|
|
}
|
|
if (!this.lastNode || this.lastNode.ID === 'root') {
|
|
this.lastNode = node;
|
|
loadNode.call(this, node, next, content);
|
|
} else {
|
|
var ethis = this;
|
|
verifyNode.call(this, this.lastNode, function () {
|
|
node.drilldown_url && node.drilldown_url.saveContentData();
|
|
node.drilldown_chart && node.drilldown_chart.saveContentData();
|
|
loadNode.call(ethis, node, function () {
|
|
ethis.lastNode = node;
|
|
next();
|
|
}, content);
|
|
});
|
|
}
|
|
}
|
|
|
|
function verifyNode(node, next, reject) {
|
|
if (!node || node.ID === 'root') {
|
|
next();
|
|
}
|
|
var type;
|
|
var opt = this.wizardCtrl.contentAreaCtrl.find('#drilldowncell_tourl');
|
|
if (opt.is(':visible')) {
|
|
type = opt.prop('checked') ? EMDrilldownType.Url : EMDrilldownType.Common;
|
|
} else {
|
|
type = node.DrilldownType;
|
|
}
|
|
if (type === EMDrilldownType.Url) {
|
|
if (node.drilldown_url == null) {
|
|
next();
|
|
} else {
|
|
node.drilldown_url.verifyContent(function () {
|
|
//node.drilldown_url.saveContentData();
|
|
next();
|
|
}, reject || function () { });
|
|
}
|
|
} else {
|
|
if (node.drilldown_chart == null) {
|
|
next();
|
|
} else {
|
|
node.drilldown_chart.verifyContent(function () {
|
|
//node.drilldown_chart.saveContentData();
|
|
next();
|
|
}, reject || function () { });
|
|
}
|
|
}
|
|
}
|
|
|
|
function insertNode(tree, root, content, append) {
|
|
var nodes = tree.getFlatData();
|
|
var n, v, max = 0;
|
|
for (var i = 0; i < nodes.length; i++) {
|
|
n = nodes[i];
|
|
if (n && /^Drilldown Cell/.test(n.Description)) {
|
|
v = parseInt(n.Description.substring(14));
|
|
if (v > max) {
|
|
max = v;
|
|
}
|
|
}
|
|
}
|
|
max++;
|
|
var node = {
|
|
ID: $.newGuid(),
|
|
Description: 'Drilldown Cell' + max,
|
|
ToUrl: {},
|
|
ToChart: {
|
|
ChartClassIID: this.wizardCtrl.dataObj.ChartClassIID
|
|
},
|
|
Header: 'Drilldown Cell' + max,
|
|
DrilldownType: EMDrilldownType.Url
|
|
};
|
|
var drilldownUrl = new $drillDownUrlCtrl(node.ToUrl);
|
|
drilldownUrl.isCellSetup = true;
|
|
drilldownUrl.wizardCtrl = this.wizardCtrl;
|
|
node.drilldown_url = drilldownUrl;
|
|
var drilldownChart = new $drillDownChartCtrl(node.ToChart);
|
|
node.drilldown_chart = drilldownChart;
|
|
drilldownChart.isCellSetup = true;
|
|
drilldownChart.tmpdata = {};
|
|
drilldownChart.wizardCtrl = this.wizardCtrl;
|
|
|
|
if (append) {
|
|
tree.insertData(node, root);
|
|
} else {
|
|
tree.insertData(node, tree.getCurrentNode(), false, true);
|
|
}
|
|
content.find('.left-tree').find('li').removeClass('selected');
|
|
content.find('#drilldowncell_tourl').prop('checked', true).change();
|
|
content.find('.content-drilldown').show();
|
|
}
|
|
|
|
function changeOption(content, node) {
|
|
var type = node && node.DrilldownType;
|
|
if (!type) {
|
|
type = content.find('#drilldowncell_tourl').prop('checked')
|
|
? EMDrilldownType.Url
|
|
: EMDrilldownType.Common;
|
|
}
|
|
content.find('.drilldown-chart-content').css('display', type === EMDrilldownType.Common ? '' : 'none');
|
|
content.find('.drilldown-url-content').css('display', type === EMDrilldownType.Url ? '' : 'none');
|
|
if (!node) {
|
|
node = content.find('.left-tree').find('li.selected').data('val');
|
|
node && (node.DrilldownType = type);
|
|
} else {
|
|
content.find('#drilldowncell_tourl').prop('checked', type === EMDrilldownType.Url);
|
|
content.find('#drilldowncell_tochart').prop('checked', type === EMDrilldownType.Common);
|
|
}
|
|
}
|
|
|
|
function getUrlDrilldown(ec) {
|
|
if (!ec) {
|
|
return {};
|
|
}
|
|
return {
|
|
DrillDowns: [
|
|
{
|
|
Type: EMDrilldownType.Url,
|
|
DrilldownUrl: [
|
|
{
|
|
BaseAddress: ec.ColumnURL,
|
|
DrilldownIID: ec.IID,
|
|
SendAuthentication: ec.SendAuthentication,
|
|
UrlParams: ec.UrlParams
|
|
}]
|
|
}]
|
|
};
|
|
}
|
|
|
|
function getChartDrilldown(ec) {
|
|
if (!ec) {
|
|
return {};
|
|
}
|
|
return {
|
|
DrillDowns: [
|
|
{
|
|
Type: EMDrilldownType.Common,
|
|
DestChartIID: ec.DestChartIID,
|
|
DrillDownFilters: $.assignArray(ec.Filters, $DrillDownFilter),
|
|
DrilldownPivots: $.assignArray(ec.Details, $DrillDownPivot),
|
|
DrilldownY: ec.ChartExtensionY ? $.assignObject(ec.ChartExtensionY, new $DrillDownY()) : null
|
|
}]
|
|
};
|
|
}
|
|
|
|
function cloneColumnLanguage(lgs, description, header) {
|
|
var langs = [];
|
|
var createObj = function (lgcode) {
|
|
return {
|
|
IID: $.newGuid(),
|
|
ColumnHeader: header || '',
|
|
ColumnTitle: description || '',
|
|
LanguageCode: lgcode
|
|
};
|
|
};
|
|
var flag = false;
|
|
for (var i = 0; i < lgs.length; i++) {
|
|
var lg = lgs[i];
|
|
if (lg.LanguageCode == _utility.currentLang) {
|
|
flag = true;
|
|
langs.push(createObj(lg.LanguageCode));
|
|
lg.ColumnHeader = header || '';
|
|
lg.ColumnTitle = description || '';
|
|
} else {
|
|
langs.push({
|
|
IID: lg.IID,
|
|
ColumnHeader: lg.ColumnHeader || '',
|
|
ColumnTitle: lg.ColumnTitle || '',
|
|
LanguageCode: lg.LanguageCode
|
|
});
|
|
}
|
|
}
|
|
if (!flag) {
|
|
var o = createObj(_utility.currentLang);
|
|
langs.push(o);
|
|
lgs.push(o);
|
|
}
|
|
return langs;
|
|
}
|
|
|
|
function toExtensionColumn(node, i) {
|
|
if (node.ColumnLanguage == null) {
|
|
node.ColumnLanguage = [];
|
|
}
|
|
var ec = {
|
|
ColumnHeader: node.Header,
|
|
ColumnLanguage: cloneColumnLanguage(node.ColumnLanguage, node.Description, node.Header),
|
|
ColumnTitle: node.Description,
|
|
IID: node.ID,
|
|
OrderIndex: i
|
|
};
|
|
var dd;
|
|
if (node.DrilldownType === EMDrilldownType.Common) {
|
|
ec.Type = 1;
|
|
ec.ColumnURL = '';
|
|
ec.SendAuthentication = 0;
|
|
ec.UrlParams = [];
|
|
|
|
dd = node.ToChart.DrillDowns[0];
|
|
ec.DestChartIID = dd.DestChartIID;
|
|
ec.Details = dd.DrilldownPivots;
|
|
ec.Filters = dd.DrillDownFilters;
|
|
ec.ChartExtensionY = dd.DrilldownY;
|
|
} else {
|
|
ec.Type = 0;
|
|
ec.DestChartIID = _utility.GuidEmpty;
|
|
ec.Details = [];
|
|
ec.Filters = [];
|
|
ec.ChartExtensionY = null;
|
|
|
|
dd = node.ToUrl.DrillDowns[0].DrilldownUrl[0];
|
|
ec.ColumnURL = dd.BaseAddress;
|
|
ec.SendAuthentication = dd.SendAuthentication ? 1 : 0;
|
|
ec.UrlParams = dd.UrlParams;
|
|
}
|
|
return ec;
|
|
}
|
|
|
|
function createOnMultiLangs(ethis, itemKey, langKey, input) {
|
|
return function () {
|
|
var lastNode = ethis.lastNode;
|
|
var langs = new $languageform();
|
|
langs.noMax = true;
|
|
var vals = [];
|
|
var obj = lastNode.ColumnLanguage;
|
|
if (obj == null) {
|
|
lastNode.ColumnLanguage = [];
|
|
}
|
|
obj = lastNode.ColumnLanguage;
|
|
for (var i = 0; i < obj.length; i++) {
|
|
var lgid = obj[i].LanguageCode;
|
|
if (lgid == _utility.currentLang) {
|
|
continue;
|
|
} else {
|
|
vals.push({
|
|
Key: lgid,
|
|
Value: obj[i][langKey]
|
|
});
|
|
}
|
|
}
|
|
vals.push({
|
|
Key: _utility.currentLang,
|
|
Value: lastNode[itemKey]
|
|
});
|
|
langs.showOpen($.getParentDomForChart(), vals, 100, function (lgs) {
|
|
for (var i = 0; i < lgs.length; i++) {
|
|
var lgid = lgs[i].Key;
|
|
var lgval = lgs[i].Value;
|
|
if (lgid == _utility.currentLang) {
|
|
lastNode[itemKey] = lgval;
|
|
input.val(lgval);
|
|
}
|
|
if ($.nullOrEmpty(lgval)) {
|
|
for (var n = 0; n < obj.length; n++) {
|
|
if (lgid == obj[n].LanguageCode) {
|
|
obj.splice(n, 1);
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
var lgitem = obj.filter(function (l) { return $.ignoreEquals(l.LanguageCode, lgid) })[0];
|
|
if (lgitem != null) {
|
|
lgitem[langKey] = lgval;
|
|
} else {
|
|
lgitem = {
|
|
IID: $.newGuid(),
|
|
LanguageCode: lgid
|
|
};
|
|
lgitem[langKey] = lgval;
|
|
obj.push(lgitem);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
langs.maskbg.css('z-index', 603);
|
|
langs.formCtrl.css('z-index', 604);
|
|
};
|
|
}
|
|
|
|
$drilldownCellSetupCtrl.prototype.createContent = function (resolve) {
|
|
var h = this.wizardCtrl.contentAreaCtrl.height();
|
|
var content = $('<div></div>').css({
|
|
'height': h,
|
|
'overflow': 'hidden'
|
|
});
|
|
var ethis = this;
|
|
|
|
content.load(window.sitePath + 'fic/Template/ChartWizard/DrilldownCellSetupCtrl.html?v=6', function () {
|
|
content.applyLanguageText(true);
|
|
|
|
var treeDiv = content.find('.left-tree');
|
|
|
|
// load nodes
|
|
var rootObj = {
|
|
ID: 'root',
|
|
Description: GetLanguageByKey('LHBIS_FIC_CLIENT_FICCONTROLS_SETDRILLDOWNTOURL_A021', 'Drilldown Cells')
|
|
};
|
|
var nodes = ethis.wizardCtrl.tmpdata.drilldownCells;
|
|
if (nodes != null) {
|
|
// tmpdata
|
|
rootObj.SubData = nodes;
|
|
} else {
|
|
nodes = ethis.wizardCtrl.dataObj.EColumns;
|
|
if (nodes != null) {
|
|
// chartItem
|
|
var ns = [];
|
|
for (var i = 0; i < nodes.length; i++) {
|
|
var n = nodes[i];
|
|
var toChart = n.Type === 1 ? getChartDrilldown(n) : {};
|
|
toChart.ChartClassIID = ethis.wizardCtrl.dataObj.ChartClassIID;
|
|
var node = {
|
|
ID: n.IID,
|
|
ChartIID: n.ChartIID,
|
|
Description: n.ColumnTitle,
|
|
ToUrl: n.Type === 0 ? getUrlDrilldown(n) : {},
|
|
ToChart: toChart,
|
|
Header: n.ColumnHeader,
|
|
DrilldownType: n.Type === 0 ? EMDrilldownType.Url : EMDrilldownType.Common,
|
|
ColumnLanguage: n.ColumnLanguage
|
|
};
|
|
var drilldownUrl = new $drillDownUrlCtrl(node.ToUrl);
|
|
drilldownUrl.isCellSetup = true;
|
|
drilldownUrl.wizardCtrl = ethis.wizardCtrl;
|
|
node.drilldown_url = drilldownUrl;
|
|
var drilldownChart = new $drillDownChartCtrl(node.ToChart);
|
|
node.drilldown_chart = drilldownChart;
|
|
drilldownChart.isCellSetup = true;
|
|
drilldownChart.tmpdata = {};
|
|
if (node.ToChart != null &&
|
|
node.ToChart.DrillDowns != null &&
|
|
node.ToChart.DrillDowns[0] != null) {
|
|
drilldownChart.tmpdata.destiid = node.ToChart.DrillDowns[0].DestChartIID;
|
|
}
|
|
drilldownChart.wizardCtrl = ethis.wizardCtrl;
|
|
ns.push(node);
|
|
}
|
|
rootObj.SubData = ns;
|
|
}
|
|
}
|
|
delete ethis.lastNode;
|
|
|
|
treeDiv.tree([rootObj], void 0, {
|
|
readonly: true,
|
|
defaultExpand: true,
|
|
willselect: onTreeSelected.bind(ethis)
|
|
});
|
|
|
|
var tree = treeDiv.data('tree');
|
|
var root = treeDiv.find('li:first');
|
|
ethis.tree = tree;
|
|
|
|
// UI event
|
|
content.find('.cell-text').change(function () {
|
|
var node = treeDiv.find('li.selected:first').data('val');
|
|
if (node) {
|
|
node.Description = $(this).val();
|
|
tree.updateData(node);
|
|
}
|
|
});
|
|
content.find('.column-header').change(function () {
|
|
var node = treeDiv.find('li.selected:first').data('val');
|
|
if (node) {
|
|
node.Header = $(this).val();
|
|
}
|
|
});
|
|
content.find('.langs-text').on('click', createOnMultiLangs(ethis, 'Description', 'ColumnTitle', content.find('.cell-text')));
|
|
content.find('.langs-header').on('click', createOnMultiLangs(ethis, 'Header', 'ColumnHeader', content.find('.column-header')));
|
|
content.find('#drilldowncell_tourl').change(function () { changeOption(content); });
|
|
content.find('#drilldowncell_tochart').change(function () { changeOption(content); });
|
|
|
|
// button event
|
|
content.find('.button-new').click(function () {
|
|
var node = treeDiv.find('li.selected').data('val');
|
|
var insert = function (append) { insertNode.call(ethis, tree, root, content, append); };
|
|
if (node && node.ID !== 'root') {
|
|
verifyNode.call(ethis, node, insert);
|
|
} else {
|
|
insert(true);
|
|
}
|
|
});
|
|
content.find('.button-del').click(function () {
|
|
var node = treeDiv.find('li.selected').data('val');
|
|
if (node && node.ID !== 'root') {
|
|
delete ethis.lastNode;
|
|
tree.removeData();
|
|
}
|
|
});
|
|
content.find('.button-up').click(function () {
|
|
var li = treeDiv.find('li.selected:first');
|
|
if (li.length) {
|
|
var index = li.index() - 1;
|
|
if (index < 0) {
|
|
return;
|
|
}
|
|
li.insertBefore(li.parent().children('li:eq(' + index + ')'));
|
|
}
|
|
});
|
|
content.find('.button-down').click(function () {
|
|
var li = treeDiv.find('li.selected:first');
|
|
if (li.length) {
|
|
var index = li.index() + 1;
|
|
var parent = li.parent();
|
|
if (index >= parent.children('li').length) {
|
|
return;
|
|
}
|
|
li.insertAfter(parent.children('li:eq(' + index + ')'));
|
|
}
|
|
});
|
|
|
|
ethis.wizardCtrl.HideProgressBar();
|
|
|
|
if (rootObj.SubData && rootObj.SubData.length > 0) {
|
|
$.delay(function () {
|
|
//root.children('ul').children('li:last').click();
|
|
var li = root.children('ul').children('li:last');
|
|
root.removeClass('selected');
|
|
li.addClass('selected');
|
|
onTreeSelected.call(ethis, li, function () {
|
|
resolve(content);
|
|
}, content);
|
|
});
|
|
} else {
|
|
resolve(content);
|
|
}
|
|
});
|
|
};
|
|
|
|
$drilldownCellSetupCtrl.prototype.verifyContent = function (resolve, reject) {
|
|
verifyNode.call(this, this.lastNode, resolve, reject);
|
|
};
|
|
|
|
$drilldownCellSetupCtrl.prototype.saveContentData = function () {
|
|
var tree = this.wizardCtrl.contentAreaCtrl.find('.left-tree').data('tree');
|
|
var nodes = tree.getFlatData().filter(function (n) { return n.ID !== 'root'; });
|
|
this.wizardCtrl.tmpdata.drilldownCells = nodes;
|
|
|
|
// fill to nodes
|
|
if (nodes != null && nodes.length > 0) {
|
|
var es = [];
|
|
for (var i = 0; i < nodes.length; i++) {
|
|
nodes[i].drilldown_url && nodes[i].drilldown_url.saveContentData();
|
|
nodes[i].drilldown_chart && nodes[i].drilldown_chart.saveContentData();
|
|
es.push(toExtensionColumn(nodes[i], i));
|
|
}
|
|
this.wizardCtrl.dataObj.EColumns = es;
|
|
} else {
|
|
this.wizardCtrl.dataObj.EColumns = [];
|
|
}
|
|
};
|
|
|
|
$drilldownCellSetupCtrl.prototype.sizeChangeOnContent = function (width, height) {
|
|
this.wizardCtrl.contentAreaCtrl.css('height', height - 8);
|
|
this.wizardCtrl.contentAreaCtrl.find('.content-box').css('height', height - 8);
|
|
this.wizardCtrl.contentAreaCtrl.find('.left-box').css('height', height - 8);
|
|
};
|
|
})();
|
|
} |