2019-1-20
1.代码比较啦一下 又全改啦
- 不小心 点啦全局的source format (应该选择编辑的区域->source->format)
- 解决方法 replace with head version
-2.测试生成 其他 主题集 的代码
- 现在连接的数据库已经创建
需求
1.owner manager 一级目录 去掉删除 移动的
2.owner manager 二级目录 编辑 有删除 移动到
3.owner manager 组件 查看改编辑 有删除 移动到
3.其他文件夹 一,二级目录 只有导出 组件 查看 克隆 导出
需求
- 系统启动创建 用户资源vfs/root/products/ebi/sys/userresource创建“其他”文件夹
- 创建主题集 应用1时 在vfs/root/products/ebi/sys/userresource 创建应用1 文件夹
- 为第二项模拟请求:http://localhost:8083/bi/taskmgr.do?action=createtask&name=应用5&appid=dcdcnd
需求
1.移动到只有应用1和下属文件夹 其他都过滤掉
/**
- 酷屏左侧面板
* - @param wnd
- @param parentElement
- @param width
- @param height
- @returns
*/
function CoolTabPanel(wnd, parentElement, width, height) {
XTabCtrl.call(this, {
});wnd : wnd || window, parentElement : parentElement, width : width, height : height, enableclosed : false, style : "gray"
this.pnode = parentElement;
this.getBodyContainer().style.padding = “0”;
this._panels = {
};cnt : 0
// 自定义控件主题集(及其控件)的角色
this.roles;
//为啦不对已有代码造成影响 把自定义组件中的主题集角色(owner manager..)json集合赋值给全局wnd
this.wnd.roles;
}
extendClass(CoolTabPanel, XTabCtrl, “CoolTabPanel”);
CoolTabPanel.WIDGET = “CoolWidgetPanel”; // 组件
CoolTabPanel.OUTLINE = “CoolOutlinePanel”; // 组件结构
CoolTabPanel.SOURCE = “CoolSourcePanel”; // 数据源
CoolTabPanel.prototype.init = function(xmlnode) {
if (!this.wnd[“XAccordionPanel”]) {// 引入js文件
sys.lib.include(“xui/ctrls/xaccordionpanel.js”);
}
var node = xmlnode.firstChild;
var i = 0;
var active = -1;
while (node) {
if (node.tagName == "panel") {
this.add(node.getAttribute('caption'), null);
if (parseBool(node.getAttribute('active'), false) === true) {
active = i;
}
var pdom = this.getBodyDom(i);
var obj = createObjectByXmlNode(pdom, node);
this.addPanel(obj, node);
i++;
}
node = node.nextSibling;
}
this._initBtns();
if (active >= 0) {
this.setActivePanel(active);
}
};
CoolTabPanel.prototype._initBtns = function() {
var lefthead = this.getHeaderContainer();
var span = lefthead.appendChild(this.doc.createElement(“span”));
g_dsn.layout.addPinBtn(span, “west”);
span = lefthead.appendChild(this.doc.createElement(“span”));
g_dsn.layout.addCloseBtn(span, “west”);
};
CoolTabPanel.prototype.getTabCount = function() {
return this._panels.cnt;
};
CoolTabPanel.prototype.getPanel = function(index) {
return this._panels[index];
};
/**
- 返回html组件所在的面板对象
* - @returns
*/
CoolTabPanel.prototype.getHtmlWidgetPanel = function() {
return this.getPanel(0).htmlWidgetPanel;
};
/**
- 获得数据源面板对象
* - @returns
*/
CoolTabPanel.prototype.getDataSourcePanel = function() {
return this[“panel” + CoolTabPanel.SOURCE];
};
CoolTabPanel.prototype.setDataSourceVisible = function(show) {
var dsobj = this[“panel” + CoolTabPanel.SOURCE];
if (!dsobj)
return;
var idx = dsobj.tabindex;
this.setTabVisible(idx, parseBool(show, true));
};
CoolTabPanel.prototype.getOutlinePanel = function() {
return this[“panel” + CoolTabPanel.OUTLINE];
};
CoolTabPanel.prototype.setOutlineVisible = function(show) {
var idx = this[“panel” + CoolTabPanel.OUTLINE].tabindex;
this.setTabVisible(idx, parseBool(show, true));
};
CoolTabPanel.prototype.getWidgetPanel = function() {
return this[“panel” + CoolTabPanel.WIDGET];
};
CoolTabPanel.prototype.setWidgetPanelVisible = function(show) {
var idx = this[“panel” + CoolTabPanel.WIDGET].tabindex;
this.setTabVisible(idx, parseBool(show, true));
};
/**
- 根据面板的对象类型
* - @param clsName
- @returns
*/
CoolTabPanel.prototype.getPanelByClass = function(clsName) {
for ( var i = 0, len = this._panels.cnt; i < len; i++) {
}var panel = this.getPanel(i); // ESENBI-10928:IE浏览器panel.constructor.name为undefined if (panel.constructor.name === clsName || panel instanceof eval(clsName)) { return panel; }
};
CoolTabPanel.prototype.addPanel = function(panel, node) {
var i = this._panels.cnt;
this._panels[i] = panel;
this._panels.cnt++;
this["panel" + node.getAttribute("object")] = panel;
panel.tabindex = i;
};
CoolTabPanel.prototype.getActivePanel = function() {
return this.getPanel(this.getActiveIndex());
};
CoolTabPanel.prototype.setActivePanel = function(index) {
this.setActive(index);
};
CoolTabPanel.prototype.dispose = function() {
// if (this.getIndex(1) !== -1) {
// $(this.getBodyDom(1).firstChild).draggable(“destroy”);
// }
// 销毁自己的对象
for ( var i = 0; i < this._panels.cnt; i++) {
var obj = this._panels[i];
if (obj && obj.dispose)
obj.dispose();
}
this._panels = null;
// 销毁父类对象
XTabCtrl.prototype.dispose.call(this);
};
function CoolWidgetPanel(wnd, parentElement, width, height) {
this.wnd = wnd || window;
this.doc = this.wnd.document;
this.pnode = parentElement;
parentElement.style.overflow = “hidden”;
this.acpanel = new window“XAccordionPanel”;
this.acpanel.container.style.height = “100%”;
this.isMaxExpanded = true;
}
CoolWidgetPanel.prototype._bindEvent = function() {
var self = this;
$(this.pnode).bind(“resize”, function() {
this.doLayout();
}.bind(this));
$(this.acpanel.container).bind(“mouseover”, this.onHover.bind(this));
$(this.acpanel.container).bind(“mouseout”, function() {
if (self.htmlWidgetPanel._timer) {
clearTimeout(self.htmlWidgetPanel._timer);
}
if (self.htmlWidgetPanel.previewpanel) {
self.htmlWidgetPanel.previewpanel.style.display = “none”;
}
});// 清除鼠标悬浮未1s执行的动作
$(this.acpanel.container).bind(“mousedown.left”,
this.onDragSatrt.bind(this));
};
CoolWidgetPanel.prototype.doLayout = function() {
if (!isCSS1Compat || this.pnode.clientHeight === 0) {
return;
}
this.acpanel.relayout();
};
CoolWidgetPanel.prototype.onDragSatrt = function(evt) {
if (this.htmlWidgetPanel.previewpanel) {
this.htmlWidgetPanel.previewpanel.style.display = “none”;
}
if (evt.which === 3) {
return;
}
var design = g_dsn.getDesign();
if (design && design.isVisible()) {
design.dragStart(evt);
}
};
CoolWidgetPanel.prototype._unbindEvent = function() {
$(this.pnode).unbind(“resize mousedown”);
$(this.acpanel.container).unbind(“mousedown.left”);
};
/**
- 获取一个临时的dom
* - @returns
*/
CoolWidgetPanel.prototype._getTempDiv = function() {
if (!this.dom4clone) {
}/* * 为了少创建克隆节点把他放到此处 */ var dom4clone = this.doc.createElement("div"); var DEFAULT_IMAGE_SIZE = 16; dom4clone.innerHTML = '<div style="position: absolute; left: 6px; width: ' + DEFAULT_IMAGE_SIZE + 'px; height: ' + DEFAULT_IMAGE_SIZE + 'px; margin: 0; background-color: #FFF; background-position: center; background-repeat: no-repeat"></div>' + '<div style="position: absolute; left: ' + (DEFAULT_IMAGE_SIZE + 10) + 'px; right: 2px; line-height: ' + DEFAULT_IMAGE_SIZE + 'px; height: ' + (DEFAULT_IMAGE_SIZE + 2) + 'px; border: 1px dotted transparent; vertical-align: middle; white-space: nowrap; overflow: hidden; text-overflow: ellipsis"></div>'; dom4clone.style.cssText += '; position: relative; height: ' + (DEFAULT_IMAGE_SIZE + 2) + 'px; cursor: pointer; border: 1px dotted transparent; margin: 5px 0 0 5px;'; this.dom4clone = dom4clone;
return this.dom4clone;
};
CoolWidgetPanel.prototype.init = function(xmlnode) {
var dom4clone = this._getTempDiv();
this.chart = parseBool(_initItemMenu(8), true);
var node = xmlnode.firstChild;
var jsarray = [];
this.vfsjs = [];// vfs中js,必须单独加载,不能批量加载,而且又可能依赖之前js,所以需要最后加载
while (node) {
if (node.tagName == ‘group’) {
jsarray = jsarray.concat(this._initGroup(node, dom4clone));
}
node = node.nextSibling;
}
this._bindEvent();
};
CoolWidgetPanel.prototype._initGroup = function(xmlnode, dom4clone) {
var caption = xmlnode.getAttribute(‘caption’);
var path = xmlnode.getAttribute(‘path’);
var id = xmlnode.getAttribute(“id”);
var expanded = xmlnode.getAttribute(“expanded”);
// html和统计图
var subpanel = this.acpanel.addSubPanel(caption, null, null);
subpanel.setId(id);
subpanel.setUndocBtnVisible(false);
subpanel.setDeleteBtnVisible(false);
if (expanded === “false”) {
subpanel.setCollapsed();
} else {
subpanel.setExpanded();
}
if (id === “customhtml”) {
// html组件单独组件
this._initCustomHtml(subpanel, xmlnode);
return;
}
var subpaneldom = subpanel.getContentDom();
var node = xmlnode.firstChild;
var jsicls = [];// war包中js
this.vfsjs = [];// vfs中的js
while (node) {
if (node.tagName === ‘cwidget’) {
var icl = this
._createWidget(subpaneldom, node, dom4clone, path, id);
if (icl && icl.indexOf(‘/vfs/‘) > -1) {
// 如果是vfs路径要单独处理,不能跟war包中路径一起加载
if (this.vfsjs.indexOf(icl) === -1)
this.vfsjs.push(icl);
} else {
if (jsicls.indexOf(icl) === -1)
jsicls.push(icl);
}
}
node = node.nextSibling;
}
return jsicls;
};
CoolWidgetPanel.prototype._initCustomHtml = function(subpanel, xmlnode) {
var htmlpanel = new CoolHTMLWidgetSubPanel(subpanel);
htmlpanel.init(xmlnode);
this.htmlWidgetPanel = htmlpanel;
};
/**
- 创建单个组件的节点
* - @param pnode
- @param xmlnode
- @param dom4clone
- @param path
*/
CoolWidgetPanel.prototype._createWidget = function(pnode, xmlnode, dom4clone,
var obj = {};path, pid) {
var atts = xmlnode.attributes;
for ( var i = 0; i < atts.length; i++) {
}obj[atts[i].name] = atts[i].value;
var objname = obj[“jsobject”] || obj[“object”];
if (this.chart === false) {
}// 没有统计图权限 if ("CWidgetGrid" != objname) return;
var objpath = obj[“path”];
var jspath = (objpath || path || “ebi/user/coolrptdsn/widget/“)
var widgetobj = pnode.appendChild(dom4clone.cloneNode(true));+ objname.toLowerCase() + ".js";
widgetobj.id = obj[“id”];
widgetobj.firstChild.setAttribute(“dragparam”, JSON.stringify(obj));
widgetobj.title = obj[“caption”];
widgetobj.lastChild.innerHTML = obj[“caption”];
widgetobj.firstChild.style.backgroundImage = ‘url(‘ + (obj[“img”]) + ‘)’;
if (pid === “elem”) {
} else {widgetobj.setAttribute("dragtype", pid);
}widgetobj.setAttribute("dragtype", "cwidget");
return jspath;
};
CoolWidgetPanel.prototype.dispose = function() {
if (this.dom4clone) {
this.dom4clone = null;
}
this._unbindEvent();
};
/**
- html组件面板
*/
function CoolHTMLWidgetSubPanel(subpanel) {
this.panel = subpanel;
this.owner = subpanel.owner;
this.wnd = this.owner.wnd;
this.doc = this.owner.doc;
}
CoolHTMLWidgetSubPanel.prototype.dispose = function() {
if (this.searcher) {
this.searcher.dispose();
}
if (this.contextMenu) {
for ( var type in this.contextMenu) {
var menu = this.contextMenu[type];
menu.dispose();
this.contextMenu[type] = null;
}
}
$(panel.container).unbind(‘mousedown’);
this.xtree.dispose();
this.xtree = null;
this.panel = null;
this.owner = null;
this.wnd = null;
this.doc = null;
};
CoolHTMLWidgetSubPanel.ACTION_URL = “edithtmlwidget.do”;
CoolHTMLWidgetSubPanel.RESOURCETREE_IMG_DIR_SYS = “ebi/user/coolrptdsn/images/widget/inner_group.png”;
CoolHTMLWidgetSubPanel.RESOURCETREE_IMG_DIR_USER = “ebi/user/coolrptdsn/images/widget/customize_group.png”;
CoolHTMLWidgetSubPanel.RESOURCETREE_IMG_SYS_HTML = “ebi/user/coolrptdsn/images/widget/inner.png”;
CoolHTMLWidgetSubPanel.RESOURCETREE_IMG_USER_HTML = “ebi/user/coolrptdsn/images/widget/customize.png”;
CoolHTMLWidgetSubPanel.RESOURCETREE_IMG_DIR = “ebi/images/lefttree/folder.gif”;
CoolHTMLWidgetSubPanel.prototype.init = function(xmlnode) {
this.typepath = xmlnode.getAttribute(“path”);
var panel = this.panel, head = panel.getTitleDom(), body = panel
.getContentDom();
body.style.overflow = “hidden”;
// 添加功能按钮”添加”
$(
‘‘)
.appendTo(head);
this._initTree(body);
this._bindEvent();
};
CoolHTMLWidgetSubPanel.prototype._initTree = function(body) {
this.xtree = new XTree(this.wnd, body);
this.xtree.dontInsertBlankNode = true;
this.xtree.setOnExpand(this._onExpandTreeItem.bind(this));
this.xtree.rootItem._loaded = true;
this.xtree.enableCtrlSelect(true);
var item = this.xtree.appendChild(I18N.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.sys", "内置组件"));
item.setItemImage(CoolHTMLWidgetSubPanel.RESOURCETREE_IMG_DIR_SYS);
item.type = "folder";
item.setHasChildren(true);
item.basepath = item.id = this.typepath + "coolsyswidget";
item.setExpanded(true);
var item = this.xtree.appendChild(I18N.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.user", "自定义组件"));
item.setItemImage(CoolHTMLWidgetSubPanel.RESOURCETREE_IMG_DIR_USER);
item.setHasChildren(true);
item.type = "folder";
item.basepath = item.id = "/root/products/ebi/sys/coolrpt/" + "cooluserwidget";
item.setExpanded(true);
this.xtree.setOnExpand(null);
};
/**
- 获取文件的请求路径
* - @param item
- @param node
*/
CoolHTMLWidgetSubPanel.prototype.getBasePath = function(item, node) {
var changeitem = item, root = this.xtree.getRootItem(), basepath;
while (root !== changeitem) {
}basepath = changeitem.basepath; if (basepath) { break; } changeitem = changeitem.getParentItem();
if (!node) {
}return basepath;
if (basepath) {
}var param = node.getAttribute("dragparam"); param = JSON.parse(param); param.basepath = basepath; node.setAttribute("dragparam", JSON.stringify(param));
};
/** - 返回item对应的vfs文件路径
* - @param item
*/
CoolHTMLWidgetSubPanel.prototype.getHtmlTreeItemPath = function(item) {
var path = [], changeitem = item;
while (!changeitem.basepath) {
}path.splice(0, 0, changeitem.id); changeitem = changeitem.getParentItem();
path.splice(0, 0, changeitem.basepath);
path = path.join(“/“);
return item.type === “widgetfile” ? (path + “.json”) : path;
};
CoolHTMLWidgetSubPanel.prototype._onExpandTreeItem = function(item) {
if (item._loaded) {
return;
}
var map = new Map();
map.put(“action”, “list”);
map.put(“basepath”, this.typepath);
map.put(“path”, item.id);
QueryObj.create(CoolHTMLWidgetSubPanel.ACTION_URL, map, function(q) {
try {
q.checkResult();
var xmldom = q.getResponseXML();
this._loadChildNodes(xmldom, item);
} catch (e) {
showError(e);
}
}.bind(this));
};
/**
- 根据xml文件加载item下的子节点
* - @param xmldom
- @param item
*/
CoolHTMLWidgetSubPanel.prototype._loadChildNodes = function(xmldom, item) {
item._loaded = true;
if (!xmldom)
xmldom = xmldom.documentElement;// 根节点return;
var id = xmldom.getAttribute(“basepath”);
item.id = id;
item.basepath = id;
item.loadFromXml(xmldom, this._addChildItem.bind(this, this.isSysPath(id)));
};
/**
- 加载节点
* - @param item
- @param node
*/
CoolHTMLWidgetSubPanel.prototype._addChildItem = function(isSys, item, node) {
var type = node.tagName;
if (type === “group”) {
} else if (type === “widget”) {this.__afterAddFolderItem(item, node.getAttribute("caption"));
}this.__afterAddWidgetItem(item, node.getAttribute("id"), node .getAttribute("caption"), node.getAttribute("img"), isSys);
};
CoolHTMLWidgetSubPanel.prototype.__afterAddFolderItem = function(childItem, id) {
childItem.id = id;
childItem.type = “folder”;
childItem.setHasChildren(true);
childItem._isLoaded = true;
childItem.setItemImage(CoolHTMLWidgetSubPanel.RESOURCETREE_IMG_DIR);
};
/**
- 添加组件节点的后续处理,设置类型和拖拽参数
* - @param childItem
- 添加的节点
- @param id
- @param cap
- @param img
- @param issyswidget
- 是否是内置组件
*/
CoolHTMLWidgetSubPanel.prototype.__afterAddWidgetItem = function(childItem, id,
cap, img, issyswidget) {
childItem.id = id;
if (!img) {
img = issyswidget ? CoolHTMLWidgetSubPanel.RESOURCETREE_IMG_SYS_HTML
: CoolHTMLWidgetSubPanel.RESOURCETREE_IMG_USER_HTML;
}
childItem.setItemImage(img);
var dragDom = this._getDragDomByItem(childItem);
if (id.startsWith(“elem”)) {
// 特殊的容器
childItem.type = “elem”;
dragDom.setAttribute(“dragtype”, “elem”);
if (id === “elem_div”) {
dragDom
} else {.setAttribute( "dragparam", JSON .stringify({ "id" : "div", "object" : "CoolElemOperator", "caption" : "div", "droppable" : "true", "defparam" : "width=300px;height=170px;bgcolor=#FFFFFF;border=1px solid #D7D7D7" }));
dragDom.setAttribute(“dragparam”, JSON.stringify({
id : id,
cap : cap
}));
}
} else {
childItem.type = “widgetfile”;
dragDom.setAttribute(“dragtype”, “chtmlwidget”);
dragDom.setAttribute(“dragparam”, JSON.stringify({
object : id,
cap : cap
}));
}
};
/**
- 前台手动添加分组
* - @param item
- 父节点
- @param childData
- 要添加的子分组节点 {cap:”文件夹名称”}
- @param beforeItem
- 要插在的节点前面
*/
CoolHTMLWidgetSubPanel.prototype._addFolderItem = function(item, childData,
beforeItem) {
var childItem = !!beforeItem ? item.insertChildBefore(childData[“cap”],
beforeItem) : item.appendChild(childData[“cap”]);
this.__afterAddFolderItem(childItem, childData[“cap”]);
childItem.selectSelf(true, false, true, true);
};
/**
- 前台手动添加组件节点
* - @param item
- 父节点
- @param childData
- 要添加的子组件节点 {cap:”文件夹名称”, id:”CHtmlWidgetxx”, img:”可空”}
- @param beforeItem
- 要插在的节点前面
*/
CoolHTMLWidgetSubPanel.prototype._addWidgetItem = function(item, childData,
beforeItem) {
var cap = childData[“cap”];
var childItem = !!beforeItem ? item.insertChildBefore(cap, beforeItem)
: item.appendChild(cap);
this
.__afterAddWidgetItem(childItem, childData[“id”], cap,
childItem.selectSelf(true, false, true, true);childData["img"]);
};
/**
- 绑定事件
*/
CoolHTMLWidgetSubPanel.prototype._bindEvent = function() {
var tree = this.xtree, panel = this.panel;
$(panel.subcontainer)
tree.setOnContextMenu(function(item, e, tree) {.bind('mousedown', this.bindMDowdAfterEvent.bind(this));
}.bind(this));if (!item) return true; if (item.type) { return this.cmd_showContextMenu(e, item); }
$(“#searchhtmlwidget”).bind(“click”, function() {
});return false;
};
/*
- @param evt
- @returns {Boolean}
*/
CoolHTMLWidgetSubPanel.prototype.bindMDowdAfterEvent = function(evt) {
var target = evt.target, id = target.id;
if (id === “searchhtmlwidget”) {
} else if (evt.which !== 3) {this.cmd_searchHtmlWidget(evt); return false;
}// 拖拽 var design = g_dsn.getDesign(); if (design && design.isVisible()) { evt.isdraghtml = true; design.dragStart(evt); }
};
/**
- 组件搜索
*/
CoolHTMLWidgetSubPanel.prototype.cmd_searchHtmlWidget = function(item) {
var searcher = this.getSearcher();
searcher.toggleShow();
};
/**
- 搜索的实际操作
* @returns
*/
CoolHTMLWidgetSubPanel.prototype.getSearcher = function() {
var searchRule = function(item, value) {var caption = item.getItemText().toUpperCase(); return caption.indexOf(value) != -1;
}.bind(this);
if (!this.searcher) {this.searcher = (function(tree, pnode, searchRule) { function Finder4HtmlWidget(tree, pnode) { this.pnode = pnode; this.xtree = tree; _initDom.call(this); _bindEvt.call(this); } function _initDom() { this.isshow = false; this.basenode = $( '<div class="searchhtmlwidget"><input type="text"/><a class="icon_search"></a></div>') .prependTo(this.pnode)[0]; this.searchInput = this.basenode.firstChild; this.searchButton = this.basenode.lastChild; } function _bindEvt() { $(this.searchInput).bind("keydown", function(e) { if (e.keyCode === 13) { this.doSearch(); return false; } else { e.stopPropagation(); } }.bind(this)); $(this.searchButton).bind("click", function(e) { this.doSearch(); }.bind(this)); } function _unbindEvt() { $(this.searchInput).unbind("keydown"); $(this.searchButton).unbind("click"); } Finder4HtmlWidget.prototype = { hide : function() { if (this.isshow) { this.pnode.style.paddingTop = "0px"; this.basenode.style.display = "none"; this.isshow = false; } }, show : function() { if (!this.isshow) { this.pnode.style.paddingTop = "24px"; this.basenode.style.display = "block"; this.searchInput.focus(); this.isshow = true; } }, toggleShow : function() { if (this.isshow) { this.hide(); } else { this.show(); } }, setSearchRule : function(func) { this.searchRule = func; }, doSearch : function(value) { var val = (value || this.searchInput.value).trim(); if (!val) return; val = val.toUpperCase(); var tree = this.xtree; tree.search(function(item, value) { return this.searchRule(item, value); }.bind(this), val, function() { tree.clearSelectedItems(); tree.setFocusItem(null); this.doSearch(); }.bind(this), true); }, dispose : function() { _unbindEvt.call(this); this.xtree = null; this.pnode = null; this.basenode = null; this.searchInput = null; this.searchButton = null; } }; var searchobj = new Finder4HtmlWidget(tree, pnode); searchobj.setSearchRule(searchRule); return searchobj; })(this.xtree, this.panel.getContentDom(), searchRule);
}
return this.searcher;
};
CoolHTMLWidgetSubPanel.prototype._createHTMLWidget = function(conf) {
for ( var i = 0, len = conf.length; i < len; i++) {
var obj = conf[i];
this.addHtmlWidgetDiv(obj);
}
};
CoolHTMLWidgetSubPanel.prototype._getDragDomByItem = function(item) {
return item.getItemDom().parentNode.firstChild;
};
CoolHTMLWidgetSubPanel.prototype.getSysRootItem = function() {
return this.xtree.getRootItem().getChildItem(0);
};
CoolHTMLWidgetSubPanel.prototype.getUserRootItem = function() {
return this.xtree.getRootItem().getChildItem(1);
};
/**
- 返回组件id为widgetId的树节点
* - @param widgetId
@returns item 可能为空
*/
CoolHTMLWidgetSubPanel.prototype.getWidgetItemById = function(widgetId) {
var rootItem = this.xtree.getRootItem();
var item = getItemById.call(rootItem, widgetId);
return item;function getItemById(id) {
for ( var i = 0; i < this.getChildrenCount(); i++) { var item = this.getChildItem(i); if (item.id === id) return item; if (item.hasChildren()) { var r = getItemById.call(item, id); if (r) return r; } }
}
};
/**
- 属性面板上会调用,返回组件id对应的组件名称
* - @param widgetId
- @returns
*/
CoolHTMLWidgetSubPanel.prototype.getWidgetCaptionById = function(widgetId) {
var item = this.getWidgetItemById(widgetId);
if (item) {
} else {return item.getItemText();
}return I18N.getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.unknown", "未知");
};
/**
- 根据组件路径返回组件的ID
*/
CoolHTMLWidgetSubPanel.prototype.getWidgetIdByPath = function(path) {
return path.substring(path.lastIndexOf(“/“) + 1, path.lastIndexOf(“.json”));
};
/**
- 判断是否是内置组件
* - @param path
- @returns
*/
CoolHTMLWidgetSubPanel.prototype.isSysPath = function(path) {
return path.endsWith(“coolsyswidget”);
};
CoolHTMLWidgetSubPanel.prototype.saveHtmlWidget = function(content, treeItem,
basepath, htmlwidgetdlg, capdlg) {
var map = new Map();
map.put(“action”, “savewidget”);
if (treeItem.type === “widgetfile”) {
map.put(“widgetId”, treeItem.id);
map.put(“widgetpath”, this.getHtmlTreeItemPath(treeItem));
} else {
// 新建保存,新建另存为 /编辑已有组件另存为
map.put(“foldpath”, this.getHtmlTreeItemPath(treeItem));
}
map.put(“definejson”, JSON.stringify(content));
map.put(“basepath”, basepath);
QueryObj
.create(
CoolHTMLWidgetSubPanel.ACTION_URL,
map,
function(q) {
try {
q.checkResult();
var res = q.getResponseText();
if (!!res) {
var wtId = res, img = content.img;
if (treeItem.type === “widgetfile”) {
wtId = treeItem.id;
} else {
// //新建保存,新建另存为 /编辑已有组件另存为
content.id = wtId;
var beforeItem = this.getBeforeItem(
treeItem, content.caption, false);
this._addWidgetItem(treeItem, {
id : wtId,
cap : content.caption,
img : img
}, beforeItem);
// 新创建的组件第一次保存的时候需要保存预览图
var param = new Map();
param.put(“path”, JSON.stringify(content));
param
.put(“folderpath”, map
.get(“basepath”));// 不带分组名
new QueryObj(
sys.getContextPath()
+ "editcoolrpt.do?action=savePreview",
param,
function(query) {
try {
query.checkResult();
if (query.isResultOk()) {
var json = query
.getResponseJSON();
if (json != null
&& json.success) {
// showWaitDialogAutoHidden(1000,
// I18N.getString("ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.savesuccess","保存预览图成功!"));
}
}
} catch (e) {
showError(e);
hideWaitDialogWithComplete();
}
});
}
// 更新缓存内容
g_dsn
.updateHtmlWidgetDefineCache(wtId,
content);
g_dsn.updateEditAreaHtmlWidget(wtId, content);
htmlwidgetdlg.close();
if (capdlg)
capdlg.close();
// if(treeItem.type === "widgetfile"){
showWaitDialogAutoHidden(
1000,
I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.saveok",
"HTML组件保存成功!"));
// }
/*
* else {
* showWaitDialog(I18N.getString("billocr.js.logfun.save",
* "HTML组件保存成功,正在保存预览图!")); }
*/
}
} catch (e) {
showError(e);
}
}.bind(this));
};
/**
- 在树上新添加节点时,需要返回它要加入的位置 后台是按照文件夹在前,文件在后,且名称从小到大排序
* - @param cap
*/
CoolHTMLWidgetSubPanel.prototype.getBeforeItem = function(pitem, cap, isFolder) {
// 添加组件 直接添加到 父节点的最下面
if (!isFolder) {
}return null;
// 添加分组 直接添加到最后一个文件夹后面,没有文件夹就添加到最前面
for ( var i = pitem.getChildrenCount() - 1; i >= 0; i–) {
}var citem = pitem.getChildItem(i); if (citem.type === "folder") { if (isFolder) { return citem.getNextSibling(); } }
return pitem.getChildItem(0);
// 返回第一个顺序大于cap的item
// for (var i = 0, len = pitem.getChildrenCount(); i < len; i++){
// var citem = pitem.getChildItem(i), txt = citem.getItemText();
// if(citem.type === “folder”){
// if(isFolder && txt > cap){
// return citem;
// }
// } else {
// if(isFolder){
// return citem;
// } else if(txt > cap){
// return citem;
// }
// }
// }
};
CoolHTMLWidgetSubPanel.prototype.cmd_previewHtmlWidget = function(e) {
if (!this.previewpanel) {
this.previewpanel = $(
“
.appendTo(this.doc.body)[0];
$(this.previewpanel.lastChild).bind(‘click’, function() {
this.previousSibling.src = “about:blank”;
this.parentElement.style.display = “none”;
return false;
});
}
var body = this.panel.getContentDom();
this.previewpanel.style.cssText += “;left:” + (body.offsetWidth + 2)
+ "px;display:block;";
var ifrm = this.previewpanel.firstChild;
// 获得组件json
var widgetPath = getXComponentByDom(e.target).id;
var cache = g_dsn.getHtmlWidgetDefineCache();
var wtjson = cache[widgetPath];
if (wtjson) {
ifrm.src = sys.getContextPath()
+ "edithtmlwidget.do?action=showpreviewpage";
$(ifrm).bind("load", function() {
$(ifrm).unbind("load");
this.contentWindow.setup(wtjson);
});
return;
}
var map = new Map();
map.put("action", "getwidgetjson");
map.put("path", widgetPath);
QueryObj.create(CoolHTMLWidgetSubPanel.ACTION_URL, map, function(q) {
try {
q.checkResult();
var wtjson = q.getResponseJSON();
cache[widgetPath] = wtjson;
ifrm.src = sys.getContextPath() + CoolHTMLWidgetSubPanel.ACTION_URL
+ "?action=showpreviewpage";
$(ifrm).bind("load", function() {
$(ifrm).unbind("load");
this.contentWindow.setup(wtjson);
});
} catch (e) {
showError(e);
}
}.bind(this));
return false;
};
/**
- 重置内置html组件
* - @param e
*/
CoolHTMLWidgetSubPanel.prototype.cmd_refreshSysHtml = function(e) {
confirmDialog(I18N.getString(“ES.COMMON.PROMPT”, “提示”), I18N.getString(
}.bind(this));"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.surereset", "确定要重置更新html组件吗?"), false, null, function() { this.doRefreshSysHtml();
};
/**
- 重置内置html组件 1.请求后台读取war包内容到vfs 2.后台返回内置组件的配置xml文件信息 3.根据xml重新加载内置组件根节点
* @param e
*/
CoolHTMLWidgetSubPanel.prototype.doRefreshSysHtml = function() {showWaitDialog(I18N.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.upating", "正在更新,请稍等......"));
var map = new Map(), self = this;
map.put(“action”, “refreshsys”);
map.put(“basepath”, this.getSysRootItem().basepath);
QueryObj.create( CoolHTMLWidgetSubPanel.ACTION_URL, map, function(q) { try { q.checkResult(); var xmldom = q.getResponseXML(); var sysItem = self.getSysRootItem(); sysItem.clearChildren(); self._loadChildNodes(xmldom, sysItem); hideWaitDialogWithComplete( 1000, I18N .getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.resentsuccess", "组件更新成功!")); } catch (e) { showError(e); return; } });
};
/**
- 导入html组件
*/
CoolHTMLWidgetSubPanel.prototype.cmd_importHtmlWidget = function(item) {
var wtItem = item.getOwner()._ownerItem;
getObjectFromRootAsync(
return false;"HtmlWidgetUploadDialog", "_HtmlWidgetUploadDialog_", true, "ebi/user/coolrptdsn/dlg/upload.js,xui/third/jquery/plugins/jquery.form.js", function(dlg) { dlg.show(); dlg.setBasepath(this.getHtmlTreeItemPath(wtItem)); dlg.setOnClose(function() { if (dlg.flag) { // 缓存处理 var map = dlg.widgetInfo; for ( var wtId in map) { var content = JSON.parse(map[wtId]); // 更新缓存内容 g_dsn.updateHtmlWidgetDefineCache(wtId, content); g_dsn.updateEditAreaHtmlWidget(wtId, content); } var usrItem = this.getUserRootItem(); dlg.flag = null; dlg.widgetInfo = null; this.xtree.setOnExpand(function() { this._onExpandTreeItem(usrItem); }.bind(this)); usrItem.setExpanded(false); usrItem.clearChildren(); usrItem._shouldHasChildren = true; usrItem._adjustExpandImg(); usrItem._loaded = false; usrItem.setExpanded(true); this.xtree.setOnExpand(null); } }.bind(this)); }.bind(this));
};
/** 树的右键菜单
*/
CoolHTMLWidgetSubPanel.prototype.cmd_showContextMenu = function(evt, item) {
var menu = null;
var basepath = this.getBasePath(item), issyspath = this.isSysPath(basepath);
if (this.xtree.getSelectedItemCount() > 1) {var items = this.xtree.getSelectedItems(); var isSys = this.isSysPath(this.getBasePath(items[0])); for ( var i = 0, len = items.length; i < len; i++) { if (this.isSysPath(this.getBasePath(items[i])) != isSys) { showMessage(I18N .getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.nosameroot", "不可以同时选择内置组件和自定义组件下的资源")); return; } else if (!!items[i].basepath) { showMessage(I18N .getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.notsameresource", "所选择的资源必须是同一类型,如选择了组件或组件分组, 那么多选的资源必须都是组件或组件分组!")); } } menu = this.getShowMenu("mutliSelets", isSys);
} else {
if (item.basepath && item.basepath.endsWith("coolsyswidget")) { // 系统内置组件跟节点 menu = this.getShowMenu("sysfolder"); } else if (item.type === "folder") { // 文件夹 if (issyspath) { menu = this.getShowMenu("sysgroup", !!item.basepath); } else { /*menu = this.getShowMenu(item.type, !!item.basepath);*/ // fangjun add pm---------------------------------------- //逻辑:取出所有主题集role(owner mana..) 将酷屏当前主题集角色取出来 不是酷屏当前主题集 全部设为reader // 自定义组件只有刷新 var self = this; //自定义组件根目录走的是 isReadOnly if (item.itemText == "自定义组件") { menu = self.getShowMenu(item.type, !!item.basepath); // 主题集文件夹 } else { //获取控件当前所在主题集名称 var presentZtj=self.wnd.g_dwSubjectSet.caption; if(presentZtj==null){ presentZtj=self.wnd.dirname; } // 1.已定义全局变量this.roles 如果为null 请求后台角色数据 var self = this; //文件夹所在主题集 var ztjItem; var item1=item; //item 可能是主题集文件夹/分组文件夹 统一变成ztjItem //主题集文件是第2级 分组文件夹 和 主题集文件都会走 把itemRole绑在主题集节点 //获得文件夹父节点 getLevel获取层级 判断是否是第2级/ if(item1.getLevel()==2){ ztjItem=item1.getParentItem(); }else{ while(item1.getLevel()!=2){ ztjItem=item1.getParentItem(); item1=item1.getParentItem(); } } if (self.roles != null) { var exit = false; var itemRole; for ( var i = 0; i < self.roles.length; i++) { if (self.roles[i].itemId == ztjItem.id) { exit = true; itemRole = self.roles[i].role; ztjItem.role=itemRole; } } // 2.如果该主题集itemId在roles里面 不请求后端数据 if (exit) { menu = self.getShowMenu(item.type, !!item.basepath, ztjItem.role,item); } else { // 3.如果该主题集itemId不在roles里面 请求后端角色数据 再显示 var self = this; var map = new Map(); map.put("action", "getRoles"); map.put("presentZtj",presentZtj); var q = QueryObj.create("edithtmlwidget.do", map); try { q.checkResult(); // 四种类型owner manager reader nopm self.roles = q.getResponseJSON(); self.wnd.roles=q.getResponseJSON(); } catch (e) { showError(e); return; } var itemRole; for ( var i = 0; i < self.roles.length; i++) { if (self.roles[i].itemId == item.id) { itemRole = self.roles[i].role; item.role=itemRole; ztjItem.role=itemRole; } } menu = self.getShowMenu(item.type, !!item.basepath, ztjItem.role,item); } } else { // 2.如果该roles为空 请求后端角色数据 再显示 var mapRoles = new Map(); mapRoles.put("action", "getRoles"); mapRoles.put("presentZtj",presentZtj); var q = QueryObj.create("edithtmlwidget.do", mapRoles); try { q.checkResult(); // 四种类型owner manager reader nopm self.roles = q.getResponseJSON(); self.wnd.roles=q.getResponseJSON(); } catch (e) { showError(e); return; } var itemRole; for ( var i = 0; i < self.roles.length; i++) { if (self.roles[i].itemId == item.id) { itemRole = self.roles[i].role; item.role=itemRole; ztjItem.role=itemRole; } } menu = self.getShowMenu(item.type, !!item.basepath, ztjItem.role,item); }
}
}
} else if (item.type === "widgetfile") {
//逻辑:控件是在当前酷屏编辑主题集下 判断 owner mana 有,无删除
//控件在其他主题集下 只有reader 角色 (和系统控件一样)
var self = this;
//控件所在主题集
var ztjItem;
var item1=item;
if(item1.getLevel()==2){
ztjItem=item1.getParentItem();
}else{
while(item1.getLevel()!=2){
ztjItem=item1.getParentItem();
item1=item1.getParentItem();
}
}
//获取控件当前所在主题集名称
var presentZtj=self.wnd.g_dwSubjectSet.caption;
if(presentZtj==null){
presentZtj=self.wnd.dirname;
}
// this.roles不为空 控件直接找
if (self.roles != null) {
// 1.如果该控件父节点主题集itemId在roles里面 不请求后端数据
var exit = false;
var itemRole;
for ( var i = 0; i < self.roles.length; i++) {
if (self.roles[i].itemId == ztjItem.id) {
exit = true;
itemRole = self.roles[i].role;
item.getParentItem().role=itemRole;
//将角色赋予主题集文件夹节点
ztjItem.role=itemRole;
}
}
if (exit) {
// 1.2 如果控件父节点在roles对象中 直接显示
menu = self.getShowMenu(item.type, issyspath,
ztjItem.role);
} else {
// 1.3 如果不在,后台获取数据显示
// 2.如果该主题集itemId不在roles里面 请求后端角色数据 再显示
var self = this;
var map = new Map();
map.put("action", "getRoles");
map.put("presentZtj",presentZtj);
var q = QueryObj.create("edithtmlwidget.do", map);
try {
q.checkResult();
// 四种类型owner manager reader nopm
self.roles = q.getResponseJSON();
self.wnd.roles=q.getResponseJSON();
} catch (e) {
showError(e);
return;
}
var itemRole;
for ( var i = 0; i < self.roles.length; i++) {
if (self.roles[i].itemId == item.getParentItem().id) {
itemRole = self.roles[i].role;
item.getParentItem().role=itemRole;
//将角色赋予主题集文件夹节点
ztjItem.role=itemRole;
}
}
menu = self.getShowMenu(item.type, issyspath,
ztjItem.role);
}
} else {
// 2.如果该主题集itemId不在roles里面 请求后端角色数据 再显示
var self = this;
var map = new Map();
map.put("action", "getRoles");
map.put("presentZtj",presentZtj);
var q = QueryObj.create("edithtmlwidget.do", map);
try {
q.checkResult();
// 四种类型owner manager reader nopm
self.roles = q.getResponseJSON();
self.wnd.roles=q.getResponseJSON();
} catch (e) {
showError(e);
return;
}
var itemRole;
for ( var i = 0; i < self.roles.length; i++) {
if (self.roles[i].itemId == ztjItem.id) {
itemRole = self.roles[i].role;
//将角色赋予主题集文件夹节点
ztjItem.role=itemRole;
}
}
menu = self.getShowMenu(item.type, issyspath, itemRole);
}
// 组件
// menu = this.getShowMenu(item.type, issyspath);
}
}
if (menu) {
menu._ownerItem = item;
menu.popupAtCursor(evt);
}
};
/**
- type:widgetfile,folder,sysfolder 内置组件根节点:更新内置组件 内置组件分组:无操作 内置组件:克隆、查看;
- 内置组件的特殊容器:无
* - 自定义组件根节点:新建html组件,新建分组,导入 自定义组件分组:新建html组件,新建分组,导入,重命名,删除
- 自定义组件:删除、克隆、编辑、重命名、导出 fangjun新增功能: 自定义组件权限:根据权限显示用户对组件可进行的操作
*/
CoolHTMLWidgetSubPanel.prototype.getShowMenu = function(type, isReadOnly, role,item) {
if (!this.wnd["XPopupMenu"]) {
include("xui/ctrls/xmenu.js");
}
if (!this.contextMenu) {
this.contextMenu = {};
}
if (!this.contextMenu[type]) {
var menuInfo = type === "sysfolder" ? [ {
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.refreshsys",
"更新内置组件"),
cmd : this.cmd_refreshSysHtml.bind(this)
} ]
: type === "folder" ? [
{
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.newwt",
"新建HTML组件"),
cmd : this.cmd_editHtmlWidget.bind(this)
},
{
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.newdir",
"新建分组"),
cmd : this.cmd_newFolder.bind(this)
},
{
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.del",
"删除"),
cmd : this.cmd_delFolder.bind(this)
},
{
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.rename",
"重命名"),
cmd : this.cmd_rename.bind(this)
},
{
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.import",
"导入"),
cmd : this.cmd_importHtmlWidget.bind(this),
},
{
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.export",
"导出"),
cmd : this.cmd_exportHtmlWidget.bind(this),
},
{
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.reload",
"刷新"),
cmd : this.cmd_reload.bind(this),
},
{
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.movetodir",
"移动到"),
cmd : this.cmd_moveTo.bind(this)
} ]
: type === "mutliSelets" ? [
{
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.del",
"删除"),
cmd : this.cmd_deleteSeletes.bind(this)
},
{
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.export",
"导出"),
cmd : this.cmd_exportHtmlWidget.bind(this)
},
{
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.movetodir",
"移动到"),
cmd : this.cmd_moveTo.bind(this)
} ]
: type === "sysgroup" ? [ {
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.export",
"导出"),
cmd : this.cmd_exportHtmlWidget.bind(this)
} ]
: [
{
icon : "",
caption : "",
cmd : this.cmd_editHtmlWidget
.bind(this)
},
{
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.del",
"删除"),
cmd : this.cmd_delHtmlWidget
.bind(this)
},
{
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.rename",
"重命名"),
cmd : this.cmd_rename
.bind(this)
},
{
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.clone",
"克隆"),
cmd : this.cmd_cloneHtmlWidget
.bind(this)
},
{
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.export",
"导出"),
cmd : this.cmd_exportHtmlWidget
.bind(this)
},
{
icon : "",
caption : I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.movetodir",
"移动到"),
cmd : this.cmd_moveTo
.bind(this)
} ];
var menu = new XPopupMenu(this.wnd);
for ( var i = 0, len = menuInfo.length; i < len; i++) {
var iteobj = menuInfo[i];
menu.addXMenuItem(iteobj["caption"], iteobj["icon"], iteobj["cmd"]);
}
this.contextMenu[type] = menu;
}
var menu;
// 多选的右键菜单
menu = this.contextMenu[type];
if (type === "folder") {
//自定义组件根目录 只有刷新 系统文件夹没有走这
if (isReadOnly) {
menu.getXMenuItem(2).setVisible(false);
menu.getXMenuItem(3).setVisible(false);
menu.getXMenuItem(5).setVisible(false);
menu.getXMenuItem(6).setVisible(true);
menu.getXMenuItem(7).setVisible(false);
menu.getXMenuItem(0).setVisible(false);
menu.getXMenuItem(1).setVisible(false);
menu.getXMenuItem(4).setVisible(false);
//非系统文件夹
} else {
/*
* menu.getXMenuItem(2).setVisible(true);
* menu.getXMenuItem(3).setVisible(true);
* menu.getXMenuItem(5).setVisible(true);
* menu.getXMenuItem(6).setVisible(false);
* menu.getXMenuItem(7).setVisible(true);
*/
//分组文件夹
if(role==null){
menu.getXMenuItem(0).setVisible(true);
menu.getXMenuItem(1).setVisible(true);
menu.getXMenuItem(2).setVisible(true);
menu.getXMenuItem(3).setVisible(false);
menu.getXMenuItem(4).setVisible(true);
menu.getXMenuItem(5).setVisible(true);
menu.getXMenuItem(6).setVisible(false);
menu.getXMenuItem(7).setVisible(false);
}
//主题集文件夹的角色
if (role == "owner") {
//判断是一级目录(getLevel==2)还是二,三级目录(getLevel!=2)
if(item.getLevel()==2){
// 0.新建html组件,1.新建分组,2..删除、3重命名、4.导入5.导出 6.刷新 7 移动到
menu.getXMenuItem(0).setVisible(true);
menu.getXMenuItem(1).setVisible(true);
menu.getXMenuItem(2).setVisible(false);
menu.getXMenuItem(3).setVisible(false);
menu.getXMenuItem(4).setVisible(true);
menu.getXMenuItem(5).setVisible(true);
menu.getXMenuItem(6).setVisible(false);
menu.getXMenuItem(7).setVisible(false);
}else{
// 0.新建html组件,1.新建分组,2..删除、3重命名、4.导入5.导出 6.刷新 7 移动到
menu.getXMenuItem(0).setVisible(true);
menu.getXMenuItem(1).setVisible(true);
menu.getXMenuItem(2).setVisible(true);
menu.getXMenuItem(3).setVisible(false);
menu.getXMenuItem(4).setVisible(true);
menu.getXMenuItem(5).setVisible(true);
menu.getXMenuItem(6).setVisible(false);
menu.getXMenuItem(7).setVisible(true);
}
}
if (role == "manager") {
//判断是一级目录(getLevel==2)还是二,三级目录(getLevel!=2)
if(item.getLevel()==2){
// 0.新建html组件,1.新建分组,2..删除、3重命名、4.导入5.导出 6.刷新 7 移动到
menu.getXMenuItem(0).setVisible(true);
menu.getXMenuItem(1).setVisible(true);
menu.getXMenuItem(2).setVisible(false);
menu.getXMenuItem(3).setVisible(false);
menu.getXMenuItem(4).setVisible(true);
menu.getXMenuItem(5).setVisible(true);
menu.getXMenuItem(6).setVisible(false);
menu.getXMenuItem(7).setVisible(false);
}else{
// 0.新建html组件,1.新建分组,2..删除、3重命名、4.导入5.导出 6.刷新 7 移动到
menu.getXMenuItem(0).setVisible(true);
menu.getXMenuItem(1).setVisible(true);
menu.getXMenuItem(2).setVisible(true);
menu.getXMenuItem(3).setVisible(false);
menu.getXMenuItem(4).setVisible(true);
menu.getXMenuItem(5).setVisible(true);
menu.getXMenuItem(6).setVisible(false);
menu.getXMenuItem(7).setVisible(true);
}
}
if (role == "reader") {
menu.getXMenuItem(0).setVisible(false);
menu.getXMenuItem(1).setVisible(false);
menu.getXMenuItem(2).setVisible(true);
menu.getXMenuItem(3).setVisible(false);
menu.getXMenuItem(4).setVisible(false);
menu.getXMenuItem(5).setVisible(true);
menu.getXMenuItem(6).setVisible(false);
menu.getXMenuItem(7).setVisible(false);
}
if (role == "nopm"||role=="notFound") {
menu.getXMenuItem(0).setVisible(false);
menu.getXMenuItem(1).setVisible(false);
menu.getXMenuItem(2).setVisible(false);
menu.getXMenuItem(3).setVisible(false);
menu.getXMenuItem(4).setVisible(false);
menu.getXMenuItem(5).setVisible(true);
menu.getXMenuItem(6).setVisible(false);
menu.getXMenuItem(7).setVisible(false);
}
}
} else if (type === "widgetfile") {
if (isReadOnly) {
menu
.getXMenuItem(0)
.setCaption(
I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.show",
"查看"));
menu.getXMenuItem(1).setVisible(false);
menu.getXMenuItem(2).setVisible(false);
menu.getXMenuItem(5).setVisible(false);
} else {
// 这里添加组件的权限判断 by fangjun
//原来是 0.编辑 1.删除、2.重命名、3.克隆4.导出 5移动到
//下面把 0,1 换啦
// menu
// .getXMenuItem(0)
// .setCaption(
// I18N
// .getString(
// “ebi.user.coolrptdsn.reporteditor.cooltabpanel.edit”,
// “编辑”));
//自定义组件之外控件 没有我写的角色 以下是默认设置
if(role==null){
menu
.getXMenuItem(0)
.setCaption(
I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.show",
"查看"));
menu.getXMenuItem(0).setVisible(true);
menu.getXMenuItem(1).setVisible(false);
menu.getXMenuItem(2).setVisible(false);
menu.getXMenuItem(3).setVisible(true);
menu.getXMenuItem(4).setVisible(true);
menu.getXMenuItem(5).setVisible(false);
}
/*
* menu.getXMenuItem(1).setVisible(false);
* menu.getXMenuItem(2).setVisible(true);
* menu.getXMenuItem(5).setVisible(true);
*/
if (role == "owner") {
menu
.getXMenuItem(0)
.setCaption(
I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.edit",
"编辑"));
// 0.查看/编辑 1.删除、2.重命名、3.克隆4.导出 5移动到
menu.getXMenuItem(0).setVisible(true);
menu.getXMenuItem(1).setVisible(true);
menu.getXMenuItem(2).setVisible(true);
menu.getXMenuItem(3).setVisible(true);
menu.getXMenuItem(4).setVisible(true);
menu.getXMenuItem(5).setVisible(true);
}
if (role == "manager") {
menu
.getXMenuItem(0)
.setCaption(
I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.edit",
"编辑"));
menu.getXMenuItem(0).setVisible(true);
menu.getXMenuItem(1).setVisible(false);
menu.getXMenuItem(2).setVisible(true);
menu.getXMenuItem(3).setVisible(true);
menu.getXMenuItem(4).setVisible(true);
menu.getXMenuItem(5).setVisible(true);
}
if (role == "reader") {
menu
.getXMenuItem(0)
.setCaption(
I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.show",
"查看"));
menu.getXMenuItem(0).setVisible(true);
menu.getXMenuItem(1).setVisible(false);
menu.getXMenuItem(2).setVisible(false);
menu.getXMenuItem(3).setVisible(true);
menu.getXMenuItem(4).setVisible(true);
menu.getXMenuItem(5).setVisible(false);
}
if (role == "nopm"||role == "notFound") {
menu
.getXMenuItem(0)
.setCaption(
I18N
.getString(
"ebi.user.coolrptdsn.reporteditor.cooltabpanel.show",
"查看"));
menu.getXMenuItem(0).setVisible(true);
menu.getXMenuItem(1).setVisible(false);
menu.getXMenuItem(2).setVisible(false);
menu.getXMenuItem(3).setVisible(true);
menu.getXMenuItem(4).setVisible(true);
menu.getXMenuItem(5).setVisible(false);
}
}
} else if (type === "mutliSelets") {
if (isReadOnly) {
menu.getXMenuItem(0).setVisible(false);
menu.getXMenuItem(2).setVisible(false);
} else {
menu.getXMenuItem(0).setVisible(true);
menu.getXMenuItem(2).setVisible(true);
}
}
return menu;
};
/**
- 新建分组
* - @param item
- XMenuItem
*/
CoolHTMLWidgetSubPanel.prototype.cmd_newFolder = function(item) {
var treeItem = item.getOwner()._ownerItem;
inputDialog(
I18N.getString(
I18N.getString("ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.foldnm", "分组名:"),
function(dlg) {"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.newdir", "新建分组"),
var cap = dlg.getValue().trim();
if (!cap) {
} else if (!this._checkFolderName(treeItem, cap)) {dlg .setHintCaption(I18N .getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.needfoldnm", "请输入分组名称!")); dlg.setHintVisible(true);
} else if (!validateFileName(cap)) {dlg .setHintCaption(I18N .getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.foldexist", "分组名已经存在!")); dlg.setHintVisible(true);
} else {dlg .setHintCaption(I18N .getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.invalidchar", "输入名称中有非法字符,操作失败.\r\n输入名称只能由汉字、字母或下划线组成。")); dlg.setHintVisible(true);
}dlg.setHintVisible(false); this.doNewFolder(treeItem, cap, dlg);
return false;
}.bind(this));
};
/** - 判断item的子节点中是否有和cap名称一样的
* - @param item
- @param cap
*/
CoolHTMLWidgetSubPanel.prototype._checkFolderName = function(parentItem, cap) {
for ( var i = 0, cnt = parentItem.getChildrenCount(); i < cnt; i++) {
}var item = parentItem.getChildItem(i); if (item.id === cap) { return false; }
return true;
};
/*
- @param item
- XTreeItem,文件夹节点
- @param cap
- 新名字
- @param dlg
- 新建分组对话框,分组创建成功才关闭
*/
CoolHTMLWidgetSubPanel.prototype.doNewFolder = function(item, cap, dlg) {
var map = new Map();
map.put(“action”, “newfolder”);
map.put(“path”, this.getHtmlTreeItemPath(item));
map.put(“name”, cap);
QueryObj
.create(
};CoolHTMLWidgetSubPanel.ACTION_URL, map, function(q) { try { q.checkResult(); var res = q.getResponseText(); if (res === "ok") { var beforeItem = this.getBeforeItem(item, cap, true); this._addFolderItem(item, { cap : cap }, beforeItem); dlg.close(); } else { showMessage(I18N .getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.adddirwrong", "添加文件夹失败,请确认该节点在资源管理器中是否被删除!")); } } catch (e) { showError(e); } }.bind(this));
CoolHTMLWidgetSubPanel.prototype.cmd_delFolder = function(item) {
confirmDialog(null, I18N.getString(
“ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.suredeldir”,
“删除分组后,分组下所有组件和分组都会删除,是否继续?”), false, null, function() {
this.doDelFolder(item);
}.bind(this));
};
CoolHTMLWidgetSubPanel.prototype.doDelFolder = function(item) {
var treeItem = item.getOwner()._ownerItem;
var map = new Map();
map.put(“action”, “delfolder”);
map.put(“basepath”, this.getBasePath(treeItem));
map.put(“path”, this.getHtmlTreeItemPath(treeItem));
QueryObj
.create(
CoolHTMLWidgetSubPanel.ACTION_URL,
map,
function(q) {
try {
q.checkResult();
// =ok:删除空文件夹;=CWidgetHtmlaaa,CWidgetHtmlbbb:删除的组件
var res = q.getResponseText();
if (!!res) {
treeItem.remove();
if (res !== “ok”) {
// 删除缓存
var dels = res.split(“,”);
for ( var i = 0, len = dels.length; i < len; i++) {
g_dsn.updateHtmlWidgetDefineCache(
dels[i], null);
}
}
showWaitDialogAutoHidden(
1000,
I18N
.getString(
“ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.deldirok”,
“文件夹删除成功!”));
}
} catch (e) {
showError(e);
}
}.bind(this));
};
/**
- 批量删除组件和分组
*/
CoolHTMLWidgetSubPanel.prototype.cmd_deleteSeletes = function() {
confirmDialog(null, I18N.getString(
}.bind(this));"ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.suredelseletes", "确定删除选中的组件和分组吗,该操作同时会删除分组下的组件?"), false, null, function() { this.doDelSeletes();
};
CoolHTMLWidgetSubPanel.prototype.doDelSeletes = function() {
var items = this.xtree.getSelectedItems();
var ids = this.getSeletesItemsId(items);
var map = new Map();
map.put(“action”, “delSeletes”);
map.put(“basepath”, this.getBasePath(items[0]));
map.put(“path”, ids);
QueryObj
.create(
CoolHTMLWidgetSubPanel.ACTION_URL,
map,
function(q) {
try {
q.checkResult();
// =ok:删除空文件夹;=CWidgetHtmlaaa,CWidgetHtmlbbb:删除的组件
var res = q.getResponseText();
if (!!res) {
for ( var i = items.length - 1; i >= 0; i–) {
if (!!items[i]) {
items[i].remove();
}
}
if (res !== “ok”) {
// 删除缓存
var dels = res.split(“,”);
for ( var i = 0, len = dels.length; i < len; i++) {
g_dsn.updateHtmlWidgetDefineCache(
dels[i], null);
}
}
showWaitDialogAutoHidden(
1000,
I18N
.getString(
“ebi.user.coolrptdsn.reporteditor.cooltabpanel.delselets”,
“所选组件和分组已经删除成功!”));
}
} catch (e) {
showError(e);
}
}.bind(this));
};
/**
- 移动功能,支持组件,分组和批量
*/
CoolHTMLWidgetSubPanel.prototype.cmd_moveTo = function() {
var items = this.xtree.getSelectedItems();
var ids = this.getSeletesItemsId(items);
var inputTitle = I18N.getString(
inputDialog("ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.inputtitle", "分组名格式示例:/分组1/分组2");
I18N.getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.foldnm", "分组名:"), I18N .getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.movetodir", "移动到"), function(dlg) { var cap = dlg.getValue().trim(); if (!cap) { dlg .setHintCaption(I18N .getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.needfoldnm", "请输入分组名称!")); dlg.setHintVisible(true); } else if (!validateFileName(cap.replace(/[\/]/g, 'a'))) { dlg .setHintCaption(I18N .getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.invalidcharnoforwardslash", "分组或者这分组路径中不能含有< > * ? : | ~ $ & ' ! = , ; + % []等字符")); dlg.setHintVisible(true); } else { dlg.setHintVisible(false); var basepath = this.getBasePath(items[0]); this.doMove(ids, cap, basepath, dlg); } return false; }.bind(this), "", "", "", { "input_text" : inputTitle });
};
/**
- 移动到
*/
CoolHTMLWidgetSubPanel.prototype.doMove = function(ids, aimdir, basepath, dlg) {
var map = new Map();
map.put(“action”, “moveTo”);
map.put(“aimdir”, aimdir);
map.put(“basepath”, basepath);
map.put(“ids”, ids);
QueryObj
};.create( CoolHTMLWidgetSubPanel.ACTION_URL, map, function(q) { try { q.checkResult(); // =ok:删除空文件夹;=CWidgetHtmlaaa,CWidgetHtmlbbb:删除的组件 var res = q.getResponseText(); if (res == "ok") { var usrItem = this.getUserRootItem(); this.xtree.setOnExpand(function() { this._onExpandTreeItem(usrItem); }.bind(this)); usrItem.setExpanded(false); usrItem.clearChildren(); usrItem._shouldHasChildren = true; usrItem._adjustExpandImg(); usrItem._loaded = false; usrItem.setExpanded(true); this.xtree.setOnExpand(null); } else { showWaitDialogAutoHidden( 1000, I18N .getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.movefail", "移动失败!")); } dlg.close(); } catch (e) { showError(e); } }.bind(this));
/**
- 获取左树选中的资源的id
*/
CoolHTMLWidgetSubPanel.prototype.getSeletesItemsId = function(items) {
var ids = “”;
for ( var i = 0, len = items.length; i < len; i++) {
}ids += this.getHtmlTreeItemPath(items[i]) + ","; ;
return ids;
};
CoolHTMLWidgetSubPanel.prototype.cmd_rename = function(item) {
var isFolder = false;
var treeItem = item.getOwner()._ownerItem;
if (treeItem.type === “folder”) {
isFolder = true;
}
var title = isFolder ? I18N.getString(
“ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.foldnm”, “分组名:”)
: I18N.getString(
“ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.wtname”,
“组件名:”);
var hint = isFolder ? I18N.getString(
“ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.needfoldnm”,
“请输入分组名称!”) : I18N.getString(
“ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.needwtnm”,
“请输入组件名称!”);
inputDialog(
title,
I18N.getString(
“ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.rename”,
“重命名”),
function(dlg) {
var cap = dlg.getValue().trim();
if (!cap) {
dlg.setHintCaption(hint);
dlg.setHintVisible(true);
} else if (cap === treeItem.itemText) {
dlg.close();
} else if (isFolder
&& !this
._checkFolderName(treeItem.getParentItem(), cap)) {
dlg
.setHintCaption(I18N
.getString(
“ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.foldexist”,
“分组名已经存在!”));
dlg.setHintVisible(true);
} else if (!validateFileName(cap)) {
dlg
.setHintCaption(I18N
.getString(
“ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.invalidchar”,
“输入名称中有非法字符,操作失败.\r\n输入名称只能由汉字、字母或下划线组成。”));
dlg.setHintVisible(true);
} else {
dlg.setHintVisible(false);
this.doRename(treeItem, cap, dlg, isFolder);
}
return false;
}.bind(this), treeItem.getItemText());
};
CoolHTMLWidgetSubPanel.prototype.doRename = function(treeItem, cap, dlg,
isFolder) {
var map = new Map();
map.put(“action”, isFolder ? “renamefolder” : “renamewidget”);
map.put(“path”, this.getHtmlTreeItemPath(treeItem));
map.put(“name”, cap);
QueryObj
.create(
CoolHTMLWidgetSubPanel.ACTION_URL,
map,
function(q) {
try {
q.checkResult();
var res = q.getResponseText();
if (res === “ok”) {
treeItem.setItemText(cap);
if (isFolder) {
treeItem.id = cap;
showWaitDialogAutoHidden(
1000,
I18N
.getString(
“ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.dirrenameok”,
“文件夹重命名成功!”));
} else {
// 更新拖拽参数、缓存中的caption以及已经拖入编辑区的组件的caption
var dragDom = this
._getDragDomByItem(treeItem);
dragDom.setAttribute(“dragparam”, JSON
.stringify({
object : treeItem.id,
cap : cap
}));
var cache = g_dsn
.getHtmlWidgetDefineCache();
if (cache[treeItem.id]) {
cache[treeItem.id].caption = cap;
var captionattr = cache[treeItem.id].comattr[1];
if (captionattr.name === “caption”) {
captionattr.defattr = cap;
}
}
var design = g_dsn.getDesign();
var widgets = design.widgets;
for ( var key in widgets) {
var widget = widgets[key];
if (widget[“referId”] == treeItem.id) {
widget.caption = cap;
widget.setCaption(cap,
!widget.option.caption);
}
}
showWaitDialogAutoHidden(
1000,
I18N
.getString(
“ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.wtrenameok”,
“HTML组件重命名成功!”));
}
dlg.close();
} else {
showMessage(I18N
.getString(
“ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.renamewrong”,
“重命名失败,请确认该资源是否存在!”));
}
} catch (e) {
showError(e);
}
}.bind(this));
};
CoolHTMLWidgetSubPanel.prototype.cmd_cloneHtmlWidget = function(item) {
var wtItem = item.getOwner()._ownerItem, basepath = this
.getBasePath(wtItem);
var map = new Map();
map.put(“action”, “clonewidget”);
map.put(“basepath”, basepath);
map.put(“caption”, wtItem.getItemText());
map.put(“path”, this.getHtmlTreeItemPath(wtItem));
QueryObj.create(CoolHTMLWidgetSubPanel.ACTION_URL, map, function(q) {
try {
q.checkResult();
var newInfo = q.getResponseJSON();
var newId = newInfo.id, newCap = newInfo.cap;
var pitem = null, beforeitem = null;
if (this.isSysPath(basepath)) {
pitem = this.getUserRootItem();
} else {
pitem = wtItem.getParentItem();
}
beforeitem = this.getBeforeItem(pitem, newCap, false);
var childData = {
cap : newCap,
id : newId
};
this._addWidgetItem(pitem, childData, beforeitem);
showWaitDialogAutoHidden(1500, I18N.getString(
“ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.cloneok”,
“组件克隆成功!”));
} catch (e) {
showError(e);
}
}.bind(this));
};
CoolHTMLWidgetSubPanel.prototype.cmd_editHtmlWidget = function(menuitem) {
var treeItem = menuitem.getOwner()._ownerItem;
this.doEditHtmlWidget(treeItem);
};
CoolHTMLWidgetSubPanel.prototype.doEditHtmlWidget = function(treeItem) {
var basepath = this.getBasePath(treeItem);
// 借用保存对话框,但是保存和添加 的事件需要修改
getObjectFromRootAsync(
“HtmlWidgetDlg”,
“HtmlWidgetDlg“,
true,
“xui/uibase.js;xui/xwindow.js;xui/ctrls/xdialog.js;ebi/user/coolrptdsn/dlg/htmlwidgetdlg.js”,
function(dlg) {
dlg.setOnSaveAs(this.saveHtmlWidget.bind(this));
dlg.setOnSave(this.saveHtmlWidget.bind(this));
dlg.show(treeItem, basepath);
}.bind(this));
return false;
};
CoolHTMLWidgetSubPanel.prototype.cmd_delHtmlWidget = function(item) {
confirmDialog(null, I18N.getString(
“ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.suredelwt”,
“组件删除后,酷屏报表中使用此组件生成的内容会失效,确定删除组件吗?”), false, null, function() {
this.doDelHtmlWidget(item);
}.bind(this));
};
CoolHTMLWidgetSubPanel.prototype.doDelHtmlWidget = function(item) {
var wtItem = item.getOwner()._ownerItem;
var map = new Map();
map.put(“action”, “deletewidget”);
map.put(“basepath”, this.getBasePath(wtItem));
map.put(“path”, this.getHtmlTreeItemPath(wtItem));
map.put(“widgetId”, wtItem.id);
QueryObj.create(CoolHTMLWidgetSubPanel.ACTION_URL, map, function(q) {
try {
q.checkResult();
var res = q.getResponseText();
wtItem.remove();
if (res === “ok”) {
g_dsn.updateHtmlWidgetDefineCache(wtItem.id, null);
}
} catch (e) {
showError(e);
}
}.bind(this));
};
/**
html组件导出
/
CoolHTMLWidgetSubPanel.prototype.cmd_exportHtmlWidget = function(item) {
var leftdom = item.getOwner()._ownerItem;
var items = this.xtree.getSelectedItems();
var ids = “”;
var ismutliselets = false;
if (items.length == 1 && items[0].type !== “folder”) {ids = items[0].id + ".json";
} else if (items.length == 1 && items[0].type === “folder”) {
ids = this.getHtmlTreeItemPath(items[0]);
} else {
// for ( var i = 0; i < items.length; i++) { // ids += this.getHtmlTreeItemPath(items[i]) + ","; // } ids = this.getSeletesItemsId(items); ismutliselets = true;
}
var url = CoolHTMLWidgetSubPanel.ACTION_URL;
if (!this.downloadForm) {var htmlfact = new HtmlElementFactory(this.wnd); this.downloadForm = htmlfact .form( getUniqueHtmlId("XFileDownloadPanel", "_Form4XFileDownloadPanel_"), null, "post", url, true, function(ifrm) { var inner = ifrm.contentWindow.document.body.innerHTML; if (inner.trim()) { getObjectFromRootAsync( "ShowMessage", "__ESEN$ShowMessage__", true, "xui/xwindow.js,xui/ctrls/xcommonctrls.js,xui/ctrls/xdialog.js", function(dlg) { dlg.setHeight(180); dlg.setOnClose(function() { dlg.setHeight(150); }); dlg.setParams(inner, "", "", ""); dlg.showModal(); }); } }); this.doc.body.appendChild(this.downloadForm); this.downloadForm.appendChild(htmlfact.edit("", "action")).value = "exportwidget"; this.downloadForm.appendChild(htmlfact.edit("", "items")); this.downloadForm.appendChild(htmlfact.edit("", "basepath")); this.downloadForm.appendChild(htmlfact.edit("", "ismutliselets")); this.downloadForm.style.display = "none";
}
var childs = this.downloadForm.getElementsByTagName(“input”);
if (!childs || childs.length != 4)return;
childs[1].value = ids;
childs[2].value = this.getBasePath(leftdom);
childs[3].value = ismutliselets;g_dsn.__notExcuteBeforeUnload = true;
this.downloadForm.submit();
};
/**
- 结构树对象
*/
function CoolOutlinePanel(wnd, parentElement, width, height) {
this.search = this._initSearch(wnd, parentElement);
var treePnode = parentElement
treePnode.style.cssText += “;position:absolute;left:0px;top:30px;right:0px;bottom:0px;”;.appendChild(wnd.document.createElement("div"));
this.tree = new XTree(wnd, treePnode, width, height);
this.conarr = [ “CHtmlWidget”, “CWidgetGrid” ];
}
CoolOutlinePanel.prototype.dispose = function() {
this.search = null;
this.tree.dispose();
this.tree = null;
};
/**
绑定事件
*/
CoolOutlinePanel.prototype.bindEvent = function() {
this.tree.setOnSelecting(this._onSelecting.bind(this));
this.tree.setOnContextMenu(this._onContextMenu.bind(this));
var self = this;
this.tree.setOnClick(function(item) {if (item) { self.cleanHighClass(); self._focusitem = item; // var editor = g_dsn.getDesign(); // if(editor.pagefloat.isVisible()){ // editor.cmd_showpagefloat(); // } }
});
/**展开时只加载直接子节点,属性initexpand记录当前节点item子节点是否已加载
*/
this.tree.setOnExpand(function(item) {
// if(!self.loaditem){
// self.refresh(item, false);
// item.userObj.initexpand = true;
// }
self.cleanHighClass();
});
this.tree.setOnCollapsed(function() {
self.cleanHighClass();
});this.search.findButton.onclick = function() {
var editor = g_dsn.getDesign();
var value = self.search.findInput.value.trim();
var widget = $(editor.basedom).find(“#” + value)[0];
if (!!widget) {search(id);
} else {
widget = editor.getWidget(value) || editor.getWidgetByName(value) || editor.getWidgetByName(value.toUpperCase()); search(!!widget ? widget.getId() : "");
}
function search(id) {
if (!id) return; var item = self.tree.rootItem.getItemById(id) || self.bodyitem; self.expandItem(item);
}
};this.search.findInput.onkeydown = function(e) {
if (e.keyCode === 13) {self.search.findButton.onclick();
} else {
return true;
}
};
eventListener.attachEvent(CoolReportPageEditor.EVENT_REPORT_LOAD+ ".outline", this.loadAll.bind(this));
eventListener.attachEvent(CoolReportPageEditor.EVENT_WIDGETFOCUS
+ ".outline", this.selectWidget.bind(this));
eventListener.attachEvent(CoolReportPageEditor.EVENT_REMOVEWIDGET
+ ".outline", this.removeWidget.bind(this));
eventListener.attachEvent(
CoolReportPageEditor.EVENT_ADDWIDGET + ".outline", this.addWidget .bind(this));
eventListener.attachEvent(CoolReportPageEditor.EVENT_WIDGETUPDATE
+ ".outline", this.updateWidget.bind(this));
eventListener.attachEvent(CoolReportPageEditor.EVENT_REFRESH + “.outline”,
this.refreshByDom.bind(this));
};
CoolOutlinePanel.prototype.unbindEvent = function() {
eventListener.detachEvent(CoolReportPageEditor.EVENT_REPORT_LOAD
+ ".outline");
eventListener.detachEvent(CoolReportPageEditor.EVENT_WIDGETFOCUS
+ ".outline");
eventListener.detachEvent(CoolReportPageEditor.EVENT_REMOVEWIDGET
+ ".outline");
eventListener
.detachEvent(CoolReportPageEditor.EVENT_ADDWIDGET + ".outline");
eventListener.detachEvent(CoolReportPageEditor.EVENT_WIDGETUPDATE
+ ".outline");
eventListener.detachEvent(CoolReportPageEditor.EVENT_REFRESH + ".outline");
};
/**
- 初始化结构树
/
CoolOutlinePanel.prototype.init = function() {
// 默认加载几个节点
this.tree
this.bodyitem = this.tree.rootItem.getItemById(“design”);.getRootItem() .loadFromArray( [ { caption : I18N .getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.editarea", "编辑区 "), id : "design", iscon : true, haschild : false } ], this.loadFinish.bind(this));
this.bodyitem.userObj = {
};pid : null, id : "design", index : 0
this.bindEvent();
};
CoolOutlinePanel.prototype._initSearch = function(wnd, parentElement) {
var doc = wnd.document;
var container = parentElement.appendChild(doc.createElement(“div”));
container.style.cssText += “width:100%;height:30px;padding:4px 2px 4px 2px;”;
container.innerHTML = “
+ "<input type='text' id='xFindInput' title='"
+ I18N
.getString(
"ebi.user.report.pagedsn.template.rpt_reporttemplate.js.72",
"输入完整的组件代号定位到组件")
+ "'>"
+ "<a id='xFindButton'><span id='searchIcon' style='width:10px;height:10px;'></span></a>"
+ "</div>";
var findInput = doc.getElementById("xFindInput");
var findButton = doc.getElementById("xFindButton");
findInput.style.cssText += ";width:100%;height:22px;border: none;font-size: 12px;padding: 1px 2px;background-color:#FFFFFF";
findButton.style.cssText += ";background: transparent url(esmain/images/search.png) no-repeat center center;width: 18px;height: 18px;border: none;cursor:pointer;position: absolute;right: 6px;top:7px;";
return {
findInput : findInput,
findButton : findButton
};
};
/**
- 装载完成
* - @param treeitem
- @param info
*/
CoolOutlinePanel.prototype.loadFinish = function(treeitem, info) {
treeitem.id = info.id;
treeitem.iscon = info.iscon;// 是否是容器,可以包含子节点
};
/**
一开始只加载design节点的直接子节点
*/
CoolOutlinePanel.prototype.loadAll = function() {
var self = this;
setTimeout(function() {self._loadding = true; self.loaditem = true; var tree = self.tree; // var item = tree.getFocusItem(); // if(item){ // tree.unSelectItem(item); // } if (tree) { var item = tree.rootItem.getItemById("design"); item.clearChildren(); } _init(item); item.selectSelf(true); delete self._loadding; delete self.loaditem;
}, 500);
function _init(rootitem) {
self.elems = 0; self.refresh(rootitem, true); var children = rootitem.childItems; if (!children || children.length < 1) return; for ( var i = 0, len = children.length; i < len; i++) { children[i].setExpanded(false); }
}
};
/**
滚动到可视区
*/
CoolOutlinePanel.prototype._scrollWidgetIntoView = function(dom) {
if (!dom)return;
if (dom.id == “editor”)
return;
var editor = g_dsn.getDesign(), pdom = editor.basedom.parentNode;
var pwidth = pdom.clientWidth, pheight = pdom.clientHeight;
if (pwidth == pdom.scrollWidth && pheight == pdom.scrollHeight)return;
while (dom.parentNode.id != “editor”) {
dom = dom.parentNode;
}
var dompos = getBoundingClientRect(dom), pdompos = getBoundingClientRect(pdom);
var left = dompos.left, right = dompos.right, width = right - left;
var top = dompos.top, bottom = dompos.bottom, height = bottom - top;
var pleft = pdompos.left, pright = pdompos.right, ptop = pdompos.top, pbottom = pdompos.bottom;
var offset = $(pdom).offset();
if (left > pleft && right > pright) {// 组件在右边if (width < pwidth) { pdom.scrollLeft += (right - pright); } else {// 组件宽度大于显示区域 pdom.scrollLeft += (left - pleft); }
} else if (left < pleft) {
pdom.scrollLeft += (left - pleft);
}
if (top > ptop && bottom > pbottom) {// 组件在下边
if (height < pheight) { pdom.scrollTop += (bottom - pbottom); } else {// 组件高度大于显示区域 pdom.scrollTop += (top - ptop); }
} else if (top < ptop) {
pdom.scrollTop += (top - ptop);
}
};
/**- 把dom滚动到pdom的可视区
* - @param dom
- @param pdom
- @param offpos
*/
CoolOutlinePanel.prototype._scrollIntoView = function(dom, pdom, offpos) {
// 在可视区不用滚动
var dompos = getBoundingClientRect(dom), pdompos = getBoundingClientRect(pdom), offtop = dom.offsetTop, offleft = dom.offsetLeft;
// 垂直滚动
if (pdom.scrollHeight > pdom.clientHeight) {
} else {if (!(dompos.height <= pdompos.height && dompos.top >= pdompos.top && dompos.bottom <= pdompos.bottom)) { pdom.scrollTop = offtop + offpos.top; offpos.top = offtop - pdom.scrollTop; }
}offpos.top += dom.offsetTop;
// 水平滚动
if (pdom.scrollWidth > pdom.clientWidth) {
} else {if (!(dompos.width <= pdompos.width && dompos.left >= pdompos.left && dompos.right <= pdompos.right)) { pdom.scrollLeft = offleft + offpos.left; offpos.left = offleft - pdom.scrollLeft; }
}offpos.left += offleft;
};
CoolOutlinePanel.prototype.cleanHighClass = function() {
var bodyitem = this.bodyitem, editor = g_dsn.getDesign();
if (bodyitem.ishight) {
removeClassName(editor.basedom, “highlight_top”);
delete bodyitem.ishight;
}
};
/**
- 组件发生变化
*/
CoolOutlinePanel.prototype.updateWidget = function(wid) {
if (this._loadding || !wid)
var editor = g_dsn.getDesign(), widget = editor.getWidget(wid);return;
var item = this.tree.rootItem.getItemById(wid);
if (item) {
}item.setItemText(this.getItemText(widget));
};
/**
- 编辑区添加了组件,树上同步添加
* - @param pid
- 父组件id或父dom
- @param wid
添加组件id或添加html元素的dom
*/
CoolOutlinePanel.prototype.addWidget = function(pid, wid) {
var self = this;
if (this._loadding)
return;
var item = this.tree.rootItem.getItemById(pid), self = this;
item = _getItem(pid, wid, item);
if (!item)
return;
setTimeout(function() {
self.loaditem = true;
self.refresh(item, true, wid);
item.selectSelf(true);
delete self.loaditem;
}, 50);function _getItem(pidOrdom, wid, item) {
if (pidOrdom instanceof HTMLElement) {
return self.getItemByHtmlElementDom(pidOrdom.id, pidOrdom);
} else if (self.isMultDroppableHtmlWidgetId(pidOrdom)) {
if ((wid instanceof HTMLElement) && $(wid).attr(“istabpage”)) {
return item;
}
var editor = g_dsn.getDesign(), tab = editor.getWidget(pidOrdom);
var index = self.getActiveIndexOfWidget(tab, wid);
var pitem = self.tree.rootItem.getItemById(pidOrdom), childitems = pitem.childItems;
for ( var i = 0; i < childitems.length; i++) {
if (i == index)return childitems[i];
}
} else {
return item;
}
}
};
/**
- 展开当前节点及上级节点
*/
CoolOutlinePanel.prototype.expandItem = function(item) {
if (!item)
var parent = item.getParentItem();return;
while (parent && parent != this.tree.rootItem) {
}if (!parent.isExpanded()) { parent.setExpanded(true); } parent = parent.getParentItem();
this.tree.selectItemSingleMode(item, false);
this._focusitem = item;
};
/**
- 编辑区选中了组件,然后高亮树 1. 编辑区选中dom,dom已经焦点了,现在只需处理item选中,触发此方法 2. 根据dom找到对应item 3.
- 设置item展开 4. 设置item选中:this.tree.selectItemSingleMode(item, false);
- this.tree.selectItemSingleMode(item, false):传false是为了不触发_onSelecting
* - @param id
- @param dom
- 选中的dom
*/
CoolOutlinePanel.prototype.selectWidget = function(id, dom) {
if (this._selectitem || id === “multwidget”)
return;
var self = this;
if (self.focustime) {
clearTimeout(self.focustime);
self.focustime = 0;
}
if (this._treeitemfocus)
return;
this.cleanHighClass();
self.focustime = setTimeout(function() {
if (isArray(id) && id.length >= 1)
id = id[0];
if (!id)
return;
showFocus(id, dom);
}, 50);
function showFocus(id, dom) {
self._widgetocus = true;
var item = self.getItemByHtmlElementDom(id, dom) || self.bodyitem;
self.expandItem(item);
delete self._widgetocus;
}
};
/**
- 选中了树,高亮编辑区的组件 1. 根据item找到对应dom 2. 展开节点item 3. 将dom显示在可视区 4. 设置dom焦点
- 设置dom焦点setFocus会触发selectWidget方法,所以通过this._selectitem属性控制不执行selectWidget方法
* - @param item
- @param e
- @param tree
*/
CoolOutlinePanel.prototype._onSelecting = function(item, e, tree) {
this._selectitem = true;
var id = item.id;
if (!id)
var pid = item.userObj.pid, wid = id;return;
if (this.isMultDroppableHtmlWidgetId(pid))
var editor = g_dsn.getDesign(), dom = editor.basedom;wid = pid;
if (id.startsWith(“elem_”)) {
} else {dom = this.getHtmlElementParentNode(item);
}dom = $(dom).find("#" + wid)[0];
this.showHtmlElementInWidget(item, dom);
this._scrollWidgetIntoView(dom);
/**- ESENBI-11637 结构树中点击灰色tab页下容器可以拖动,拖出后无法还原 add by xiaoshan 2018.6.14
- 容器组件的容器让其不让选中让其拖动
*/
if (item.userObj.istabpage) {
var pwidget = editor.getWidget(item.userObj.pid);
dom = pwidget.getBaseDom();
id = pid;
}
if (id.startsWith(“elem_”))
id = “elem”;
editor.setFocus(true, id, dom, false);
delete this._selectitem;
};
/**
- 展开节点 当节点没有展开,处理item展开
* - @param item
- @param dom
- item对应的dom
*/
CoolOutlinePanel.prototype.showHtmlElementInWidget = function(item, dom) {
if (!item)
return;
if (item.id == “design”)
return;
var id = item.id;
var parent = item, editor = g_dsn.getDesign();
while (id != “design”) {
if (this.isMultDroppableHtmlWidgetId(parent.userObj.pid)) {
var widget = editor.getWidget(parent.userObj.pid);
var curindex = widget.getActiveIndex();
var index = this.getActiveIndexOfWidget(widget, dom);
if (curindex != index) {
widget.setActiveIndex(index);
}
}
parent = parent.getParentItem();
id = parent.id;
}
};
/**
- 编辑区删除组件,树上同步删除
* - @param delitem
- 待删除的item或”elem”
- @param indexOrdom
- 待删除dom
- @param isreposition
- 是否是拖动组件,即组件父组件改变了,需要先删除原父组件中的组件,再在新父组件创建
*/
CoolOutlinePanel.prototype.removeWidget = function(delitem, indexOrdom,
isreposition) {
var item = this._focusitem;
if (indexOrdom instanceof HTMLElement)
item = this.getItemByHtmlElementDom(indexOrdom.id, indexOrdom);
if (item) {
var parent = item.getParentItem();
this.updateItemAfterRemove(parent, item);
item.remove(1);
this._checkIcon(parent, item);
eventListener.fireEvent(CoolDesignEditor.EVENT_FOCUS, [ “design” ]);
eventListener.fireEvent(CoolReportPageEditor.EVENT_WIDGETFOCUS,
[ “design” ]);
}
};
/**
- 树上删除节点 根据删除节点,找到节点对应的dom,再删除dom
* - @param treeitem
- @param isdelfromtree
- true表示通过从结构树上删除,false表示通过组件上点击dom删除
- @param deldom
- 待删除dom
*/
CoolOutlinePanel.prototype.deleteWidget = function(treeitem, isdelfromtree,
deldom) {
if (!treeitem)
return;
var editor = g_dsn.getDesign();
editor.cmd_delWidget();
};
CoolOutlinePanel.prototype.isWidget = function(id) {
var widget = g_dsn.getWidgetById(id);
return widget ? true : false;
};
/** - 结构树item删除后更新其他item索引
* - @param pitem
- 删除节点的父item
- @param item
待删除的item
*/
CoolOutlinePanel.prototype.updateItemAfterRemove = function(pitem, item) {
// 组件的索引始终是0,不需要更新
if (!pitem || this.isWidget(item.id))
return;
var self = this;
if (pitem.id == “design” || this.isMultDroppableHtmlWidgetId(pitem.id)) {
var items = pitem.childItems, index = item.userObj.index;
updateIndex(items, index);
} else if (item.id.startsWith(“elem“)) {
_updateItem(pitem, item);
}function _updateIndex(items, index) {
for ( var i = index + 1; i < items.length; i++) {
var child = items[i];
if (child && !self.isCHtmlWidget(child.id)) {
child.userObj.index -= 1;
}
}
}function _updateItem(pitem, item) {
var count = pitem.getChildrenCount(), index = item.userObj.index;
for ( var i = 0; i < count; i++) {
var child = pitem.getChildItem(i), userobj = child.userObj;
if (userobj.iselem && userobj.index > index) {
userobj.index -= 1;
}
}
}
};
/**
- 根据id或dom获取结构树item
* - @param id
- item.id或elem
- @param index
- 当前id为elem,index为item对应的dom,当前id为多个标签页组件id,index表示当前item的索引
*/
CoolOutlinePanel.prototype.getItemById = function(id, index) {
var item;
if (id == “elem” && index instanceof HTMLElement) {
item = this.getItemByHtmlElementDom(id, index);
} else {
item = this.tree.rootItem.getItemById(id);
}
if (this.isMultDroppableHtmlWidgetId(id)) {
return item.getChildItem(index);
}
return item;
};
/**
- 检查图标,
* - @param rootitem
- @param isRecursion
*/
CoolOutlinePanel.prototype.doCheckIcon = function(rootitem, isRecursion) {
rootitem = rootitem || this.tree.rootItem;
var child = rootitem.childItems;
if (!child)
for ( var i = 0, len = child.length; i < len; i++) {return;
}var item = child[i]; if (this._checkIcon(item) && isRecursion === true) { this.doCheckIcon(item, isRecursion); }
};
CoolOutlinePanel.prototype.createNewElementId = function() {
if (!this.elems)
this.elems = 0;
this.elems++;
return id = “elem_” + this.elems;
};
/**
- 检查是否有展开图标 1.添加组件时需要检查图标,delitem为null 2.删除组件时,delitem为待删除item
* - @param item
- 父item
- @param delitem
- 待删除的item
- @returns
*/
CoolOutlinePanel.prototype._checkIcon = function(item, delitem) {
if (!item.iscon)
var hasicon = false;return;
if (delitem instanceof XTreeItem) {
} else {for ( var i = 0, count = item.getChildrenCount(); i < count; i++) { if (item.getChildItem(i) == delitem) continue; hasicon = true; }
}hasicon = this.hasChildren(item.id);
item.setHasChildren(hasicon);
return hasicon;
};
/**
- 判断cwidget是否需要过滤
*/
CoolOutlinePanel.prototype.isFilterCWidget = function(id, iscwidget) {
if (!id)
if (iscwidget && this.isCWidgetId(id))return false;
return false;return true;
};
/**
- 是否过滤用于显示组件焦点的element
*/
CoolOutlinePanel.prototype.isFilterWidgetFocusElement = function(classname) {
if (!classname)
if (classname.trim().startsWith(“widget_focus”))return false;
return false;return true;
};
/**
- 当前设计区dom被选中,会有选中状态,是通过添加html元素实现的 添加的html元素classname是以widget_focus开头的
*/
CoolOutlinePanel.prototype.isFocusHtmlElement = function(dom) {
if (!(dom instanceof HTMLElement))
return this.isFilterWidgetFocusElement(dom.className);return false;
};
/**
- 当拖入一个田字布局,dom的classname为”defelement widget_Multfocus”
- 拖入完成后widget_Multfocus就成多余的了,需要去掉widget_Multfocus
*/
CoolOutlinePanel.prototype.getEffectiveClassName = function(classname) {
classname = classname.replace(“widget_Multfocus”, “”);
return classname.trim();
};
/**
- 过滤选中时的用于焦点的html元素,返回pnode的子节点数组
*/
CoolOutlinePanel.prototype.getEffectiveChildNodes = function(pnode) {
var childs = pnode.children, len = childs.length;
var nodes = [];
for ( var i = 0; i < len; i++) {
}var child = childs[i]; if (this.isFocusHtmlElement(child) || this.isCWidgetId(child.id)) continue; nodes.push(child);
return nodes;
};
/**
- 获取目标dom在父dom中的索引
* - @param childs
- 父dom的子节点数组
- @param target
- 目标dom
*/
CoolOutlinePanel.prototype.getHtmlElementIndex = function(childs, target) {
var index = 0;
if (childs && childs.length > 0) {
for ( var i = 0, len = childs.length; i < len; i++) {
if (childs[i] === target)
return i;
// if(!this.isCWidgetId(childs[i].id)) {
// index ++;
// }
}
}
return 0;
};
CoolOutlinePanel.prototype.hasChildElement = function(dom) {
if (!dom)
return false;
var childs = Array.isArray(dom) ? dom : dom.children, len = childs.length;
for ( var i = 0; i < len; i++) {
if (this.isFocusHtmlElement(childs[i]))
continue;
return true;
}
return false;
};
/**
- 判断id对应的item是否有子节点
* - @param id
- item节点的id
- @param eledom
- 当id以elem_开头,即是元素节点,elemdom表示元素节点的dom,可为空
*/
CoolOutlinePanel.prototype.hasChildren = function(id, elemdom) {
if (!id)
return false;
var editor = g_dsn.getDesign(), widget = editor.getWidget(id);
if (id == “design”) {
return this.hasChildElement(editor.basedom);
} else if (id.startsWith(“elem_”)) {
if (!elemdom) {
var item = this.tree.rootItem.getItemById(id);
elemdom = this.getHtmlElementParentNode(item);
}
return this.hasChildElement(elemdom);
}
if (widget) {
if (widget.ishtmlwidget) {
if (!widget.$droppabledom)
return false;
for ( var i = 0; i < widget.$droppabledom.length; i++) {
if (this.hasChildElement(widget.$droppabledom[i]))
}return true;
return false;
} else {
return !$.isEmptyObject(widget.childnodes);
}
}
var dom = $(editor.basedom).find(“#” + id)[0];
return !!dom && dom.children.length > 0;
};
/**
- 根据id判断对应是否为cwidget组件
*/
CoolOutlinePanel.prototype.isCWidgetId = function(id) {
if (!id)
var editor = g_dsn.getDesign(), widget = editor.getWidget(id);return false;
if (widget instanceof CWidget)
return false;return true;
};
/**
- 根据id判断对应是否为chtmlwidget组件
*/
CoolOutlinePanel.prototype.isCHtmlWidget = function(id) {
if (!id)
var editor = g_dsn.getDesign(), widget = editor.getWidget(id);return false;
if (widget && widget.ishtmlwidget)
return false;return true;
};
/**
- 判断是否是容器元素 如单容器,田字布局
*/
CoolOutlinePanel.prototype.isContainerElement = function(dom) {
return $(dom).hasClass(“defelement”)
};&& dom.getAttribute("droppable") == "true";
CoolOutlinePanel.EDITOR = “editor”;
CoolOutlinePanel.DESIGN = “design”;
/**
- 根据id判断
*/
CoolOutlinePanel.prototype.isHtmlElementId = function(domid) {
if (!domid)
if (domid == CoolOutlinePanel.EDITOR || domid == “editor”)return true;
var editor = g_dsn.getDesign(), widget = editor.getWidget(domid);return false;
if (widget && !domid.startsWith(“elem”))
return true;return false;
};
/**
- 根据点击的dom查找对应的item
* - @param id
- 点击dom的id或wid
- @param dom
- 点击的dom
*/
CoolOutlinePanel.prototype.getItemByHtmlElementDom = function(id, dom) {
if (id == CoolOutlinePanel.DESIGN || id == “multwidget”)
return;
if (dom && dom.id == “editor”)
return this.tree.rootItem.getItemById(CoolOutlinePanel.DESIGN);
if (dom && this.isCWidgetId(dom.id)) {
var editor = g_dsn.getDesign(), widget = editor.getWidget(id);
if (widget.basedom == dom) {
return this.tree.rootItem.getItemById(id);
}
}
var self = this, id = id ? id : dom.id, parent = dom;
while (this.isHtmlElementId(id)) {
parent = parent.parentElement;
id = parent.id;
}
function _isHtmlElementDom(id) {
if (id == CoolOutlinePanel.EDITOR)
return false;
if (id == “”) {
return true;
} else if (self.isCHtmlWidget(id)) {
return false;
} else if (self.isContainerElement(dom)) {
return true;
}
return false;
}
if (id == CoolOutlinePanel.EDITOR)
id = CoolOutlinePanel.DESIGN;
var item = this.tree.rootItem.getItemById(id), count = item
.getChildrenCount();
return this.getItemByItem(item, count, dom, parent);
};
/**
- 通过已知item找到dom对应的item
* - @param item
- 当前item 是dom对应item的上级节点
- @param count
- 当前item的子节点个数
- @param dom
- 选中的dom
- @param parent
- 当前item对应的dom
*/
CoolOutlinePanel.prototype.getItemByItem = function(item, count, dom, parent) {
var target = null;
for ( var i = 0; i < count; i++) {
var child = item.getChildItem(i);
var cdom = this.getHtmlElementDomByItem(child, parent);
if (cdom == dom) {
target = child;
break;
}
target = this.getItemByItem(child, child.getChildrenCount(), dom, cdom);
if (target)
return target;
}
return target;
};
CoolOutlinePanel.prototype.getHtmlElementDomByItemId = function(itemid, basedom) {
var item = this.tree.rootItem.getItemById(itemid);
return this.getHtmlElementDomByItem(item, basedom);
};
/**
- 根据结构树上item获取对应组件的basedom obj = item.userObj
- 1.obj.id存在,根据id直接获取dom,如果是html容器组件,需要找到 2.obj.classname存在,获取
- 3.obj.id和obj.classname都不存在,直接获取basedom.children,通过索引index获取
* - @param item
- item对象
- @param basedom
- item对应dom的父节点
*/
CoolOutlinePanel.prototype.getHtmlElementDomByItem = function(item, basedom) {
var editor = g_dsn.getDesign(), userObj = item.userObj;
if (item.id == “design”)
return editor.basedom;
var id = userObj.id, classname = userObj.classname, index = userObj.index;
if (id) {
basedom = $(basedom).find(“#” + id)[0];
// var widget = editor.getWidget(id);
// basedom = this.getCHtmlWidgetDroppableDom(widget, basedom, index);
} else if (classname) {
basedom = this.getCHtmlWidgetDroppableDom(classname, basedom, index);
} else {
basedom = basedom.children[index];
}
return basedom;
};
/**
- 根据索引获取容器类html组件的子组件的dom
* - @param classname
- 子组件dom的classname
- @param basedom
- 子组件的直接父dom
- @param index
- 子组件在直接父dom中索引
/
CoolOutlinePanel.prototype.getCHtmlWidgetDroppableDom = function(classname,
basedom, index) {
var htmlwidget = g_dsn.getDesign().getWidget(basedom.id);
if (htmlwidget && htmlwidget.ishtmlwidget) {
basedom = this._getCWidgetDroppableDom(htmlwidget);
// if(this.isMultDroppableHtmlWidget(htmlwidget)){// ESENBI-10958
// this.setActiveIndexForWidget(htmlwidget, index);
// }
// for(var i = 0; i < basedom.length; i++){
// if(i == index) return basedom[i];
// }
return basedom[index];
} else {
var cnodes = this.getEffectiveChildNodes(basedom)/
var realidx = 0;// 比较的时候要除掉组件的dom* , count = * childdom.length */;
for ( var i = 0, len = cnodes.length; i < len; i++) {
var cnode = cnodes[i];
if ($(cnode).hasClass(classname) && index === realidx) {
return cnode;
}
realidx++;
}
}
return basedom;
};
/*
- @param widget
- 容器类html组件对象或父dom
*/
CoolOutlinePanel.prototype._getCWidgetDroppableDom = function(widgetOrdom,
iscwidget) {
var iswidget = widgetOrdom instanceof CHtmlWidget;
var dom = iswidget ? widgetOrdom.$droppabledom : widgetOrdom.children, arr = [];
if (!dom)
return arr;
for ( var i = 0; i < dom.length; i++) {
var cdom = dom[i], id = cdom.id, classname = cdom.className.trim();
if (this.isFilterCWidget(id, iscwidget)
|| this.isFilterWidgetFocusElement(classname))
continue;
arr.push(dom[i]);
}
if (iswidget && !this.isMultDroppableHtmlWidget(widgetOrdom)) {
return this._getCWidgetDroppableDom(arr[0], false);
}
return arr;
};
/**
- 根据item(item.id以elem_开头)查找对应dom的父节点
*/
CoolOutlinePanel.prototype.getHtmlElementParentNode = function(item) {
var editor = g_dsn.getDesign(), basedom = editor.basedom;
if (!item)
var id = item.id, parentItem = item.getParentItem();return basedom;
var obj = {
};tid : id
while (parentItem.id != “design”) {
}obj = { obj : obj }; id = parentItem.id; obj.tid = id; if (!id.startsWith("elem_")) break; parentItem = parentItem.getParentItem();
if (parentItem.id == “design”) {
}obj = { obj : obj, tid : "design" }
while (obj.obj) {
}id = obj.tid, obj = obj.obj; basedom = this.getHtmlElementDomByItemId(id, basedom);
basedom = this.getHtmlElementDomByItemId(obj.tid, basedom);
return basedom;
};
/**
- 根据id判断当前组件是否有标签页节点item
*/
CoolOutlinePanel.prototype.isMultDroppableHtmlWidgetId = function(wid) {
if (!wid)
var editor = g_dsn.getDesign(), widget = editor.getWidget(wid);return false;
return this.isMultDroppableHtmlWidget(widget);
};
/**
- 判断当前htmlwidget是否有多个标签页节点item
*/
CoolOutlinePanel.prototype.isMultDroppableHtmlWidget = function(widget) {
if (!(widget instanceof CWidget))
if (!widget.ishtmlwidget)return false;
if (!widget.$droppabledom)return false;
if (widget.$droppabledom.length > 1)return false;
var dom = widget.$droppabledom[0];return true;
if ($(dom).attr(“istabpage”))
return false;return true;
};
/**
- 获取有多个标签页节点item的组件的激活页索引 前提 :调用this.isMultDroppableHtmlWidget(widget)返回true
* - @param widget
- 有多标签页的组件
- @param widordom
*/
CoolOutlinePanel.prototype.getActiveIndexOfWidget = function(widget, widordom) {
var droppabledoms = widget.$droppabledom, len = droppabledoms.length;
if (widordom && !(widordom instanceof HTMLElement)
}&& this.isCWidgetId(widordom)) { var basedom = g_dsn.getDesign().basedom; widordom = $(basedom).find("#" + widordom)[0];
for ( var i = 0; i < len; i++) {
}var droppabledom = droppabledoms[i]; if (droppabledom == widordom || $(droppabledom).find(widordom)[0]) return i;
return 0;
};
/**
- 多标签页的组件切换标签
* - @param widget
- 多标签页的组件,如tab
- @param index
- 激活页
*/
CoolOutlinePanel.prototype.setActiveIndexForWidget = function(widget, index) {
widget.setProperty(“activeTab”, index);
};
/**
- 复制粘贴嵌套的组件,刷新结构树
*/
CoolOutlinePanel.prototype.refreshByDom = function(pdom) {
if (!pdom || pdom.children.length == 0)
var childs = pdom.children, len = childs.length;return;
for ( var i = 0; i < len; i++) {
}var child = childs[i]; if (!child) continue; var wid = child.getAttribute("wid"), classname = this .getEffectiveClassName(child.className); if (this.tree.rootItem.getItemById(wid)) continue; if (this.isFilterWidgetFocusElement(classname)) continue; if (child.getAttribute("idle") == "true") continue; if (child.tagName === "WIDGET" && !!child.getAttribute("wid")) continue; if (this.getItemByHtmlElementDom(child.id, child)) continue; this.addWidget(pdom, child);
};
/**
- 刷新、展开节点
* - @param rootitem
- 待刷新节点(父item
- @param isRecursion
- 是否刷新rootitem的子item
- @param wid
添加组件id或dom
*/
CoolOutlinePanel.prototype.refresh = function(rootitem, isRecursion, wid) {
rootitem = rootitem || this.tree.rootItem.getItemById(“design”);
if (rootitem.id) {
this.__refreshItem(rootitem, wid);
}
var self = this;
if (isRecursion) {
var children = rootitem.childItems;
if (!children || children.length < 1)
return;
for ( var i = 0, len = children.length; i < len; i++) {
var child = children[i];
if (needExpand(child, wid)) {
var expand = child.isExpanded();
this.refresh(child, isRecursion);
if (!expand) {child.setExpanded(false);
}
}
}
}function needExpand(item, widOrdom) {
if (!item)
return false;
if (!widOrdom)
return true;
if (item.id == widOrdom)
return true;
if (widOrdom instanceof HTMLElement
&& !(widOrdom.tagName === “WIDGET” && !!widOrdom.getAttribute("wid"))) {
if (item.id == widOrdom.id)
return true;
var target = self.getItemByHtmlElementDom(widOrdom.id, widOrdom);
if (item.id == target.id)
return true;
}
return false;
}
};
/**
- 1、刷新这个item的图标,从无到有,或者从右到无 2、如果这个节点是展开,刷新子节点(可能被删除或者添加修改)
* - @param item
- 父item
- @param wid
- 待添加item的wid
*/
CoolOutlinePanel.prototype.__refreshItem = function(item, wid) {
this._onExpand(item, wid);
if (item.iscon) {
this._checkIcon(item);
}
};
/**
- 展开节点, 每次展开的时候都检查一下
* - @param item
- 父item
- @param widgetid
添加组件时的组件id
*/
CoolOutlinePanel.prototype._onExpand = function(item, widgetid) {
var id = item.id;
if (!id)
return;
if (!item.iscon)
return;
var editor = g_dsn.getDesign(), widget = editor.getWidget(id);
var itemobj = item.userObj, pid = id;
var basedom = editor.basedom, childnodes = basedom.children;
if (widgetid) {
childnodes = [ _getCHtmlWidgetBaseDom(basedom, widgetid) ];
} else if (widget && widget.ishtmlwidget) {
childnodes = this.getCWidgetDroppableDom(widget);
} else if (id.startsWith(“elem“)) {
childnodes = this.getHtmlElementParentNode(item).children;
} else if (id != “design”) {
childnodes = _getCHtmlWidgetBaseDom(basedom, id).children;
}
var infos = [], caption, icon, iselem = false, isdroppable = false, istabpage = false;
var len = childnodes.length;
if (len == 0)
return;
for ( var i = 0; i < len; i++) {
var childnode = childnodes[i], index = i;
if (!childnode)
continue;
var wid = childnode.getAttribute(“wid”), classname = this
.getEffectiveClassName(childnode.className);
if (this.tree.rootItem.getItemById(wid))
continue;
if (this.isFocusHtmlElement(childnode))
continue;
if (childnode.getAttribute(“idle”) == “true”)
continue;
if (childnode.tagName === “WIDGET” && !!childnode.getAttribute(“wid”))
continue;
if (this.getItemByHtmlElementDom(childnode.id, childnode))
continue;if (wid && wid != “elem”) {
var cw = editor.getWidget(wid);
caption = this.getItemText(cw);
icon = cw.ishtmlwidget ? (cw.$droppabledom != null) : false;
} else if (childnode instanceof HTMLElement) {
wid = this.createNewElementId();
if (this.isMultDroppableHtmlWidget(widget)) {
caption = I18N.getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.tabpages", "容器");
icon = true;
index = this.getIndexByItem(item, i);
istabpage = true;
} else if ($(childnode).hasClass(“defelement”)) {
caption = I18N.getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.onecontrainer", "单容器");
icon = true;
index = this.getIndexByItem(item, i, childnode);
iselem = true;
isdroppable = true;
} else {
caption = childnode.id || “”;
caption = I18N.getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.htmlelement", "HTML元素") + (!!caption ? (" (" + caption + ")") : "");
icon = childnode.children.length > 0;
index = this.getIndexByItem(item, i, childnode);
iselem = true;
}
}
var info = {
caption : caption,
id : wid,
iscon : icon,
haschild : this.hasChildren(wid, childnode),
userObj : {
pid : pid,
id : childnode.id,
classname : classname,
index : index,
iselem : iselem,
isdroppable : isdroppable,
istabpage : istabpage,
initexpand : true
}
};
infos.push(info);
}
// _clear(childitem);
item.loadFromArray(infos, this.loadFinish.bind(this));function _clear(arr) {
for ( var i = 0, len = arr.length; i < len; i++) {
if (arr[i]) {
arr[i].remove();
}
}
}
function _indexOfId(arr, id) {
for ( var i = 0, len = arr.length; i < len; i++) {
if (arr[i].id == id) {
arr.splice(i, 1);
return true;
}
}
return false;
}function getChildItems(item) {
var arr = item.childItems ? item.childItems.slice(0) : [];
for ( var i = arr.length - 1; i >= 0; i–) {
if (arr[i] && arr[i].id.startsWith(“elem“)) {
arr.splice(i, 1);
}
}
return arr;
}function _isHtmlDom(dom, id) {
if (!id)
return false;
var editor = g_dsn.getDesign, basedom = $(editor.basedom)
.find(“#” + id)[0];
if (basedom != dom)
return true;
return false;
}
;function _getCHtmlWidgetBaseDom(basedom, id) {
if (id instanceof HTMLElement)
return id;
var dom = $(basedom).find(“#” + id)[0];
if (dom)
return dom;
return document.getElementById(id);
}
};
/**
- 获取待创建item对应的dom在父item对应的dom中的索引 1.item是tab组件,index就是其索引, htmldom为null
- 2.item是一般的cwidget组件,因为有id, 索引为0 3.item为htmlelement, htmldom就是对应的dom,
- 需要获取htmldom在父元素中索引
* - @param item
- 父item
- @param index
- 默认的索引
- @param htmldom
*/
CoolOutlinePanel.prototype.getIndexByItem = function(item, index, htmldom) {
if (!index)
if (!item)index = 0;
if (htmldom/ && $(htmldom).hasClass(“defelement”) /) {return index;
}var parent = htmldom.parentElement; var childs = this.getEffectiveChildNodes(parent); return this.getHtmlElementIndex(childs, htmldom);
var count = item.getChildrenCount();
if (count == 0)
return count;return index;
};
CoolOutlinePanel.prototype.getItemText = function(widget) {
if (!widget)
return “”;
var caption = “”;
if (widget.ishtmlwidget) {
caption = widget.getCaption();
if (!caption) {
caption = widget.getPptCaption();
}
} else {
var wid = widget.id;
wid = /[A-Za-z]+/.exec(wid)[0];
caption = this.getCaption(wid, widget);
}
return caption + “ (” + widget.getName() + “)”;
};
CoolOutlinePanel.prototype.getCaption = function(wid, widget) {
var caption = widget.tagname;
switch (wid) {
case “CWidgetGrid”:
caption = I18N.getString(
“ebi.user.coolrptdsn.reporteditor.coolproppanel.js.gird”,
“可视化表格”);
break;
case “CWidgetChart”:
caption = I18N.getString(
“ebi.user.coolrptdsn.reporteditor.coolproppanel.js.chart”,
“统计图”);
break;
case “CWidgetMap”:
caption = I18N.getString(
“ebi.user.coolrptdsn.reporteditor.coolproppanel.js.ditu”, “地图”);
break;
case “CWidgetMiniChart”:
caption = I18N.getString(
“ebi.user.coolrptdsn.reporteditor.coolproppanel.js.minichart”,
“迷你图”);
break;
}
return caption;
};
/**
- 右键菜单
* - @param item
- @param e
@param tree
*/
CoolOutlinePanel.prototype._onContextMenu = function(item, e, tree) {
this._onSelecting(item, e, tree);
if (!this.menu) {this.menu = new XPopupMenu(this.wnd); this.menu.deleteitem = this.menu .addXMenuItem( I18N .getString( "ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.contextmenu.delete", "删除"), null); // this.menu.refreshitem = // this.menu.addXMenuItem(I18N.getString("ebi.user.coolrptdsn.reporteditor.cooltabpanel.js.contextmenu.refresh","刷新"), // null);
}
var id = item.id, editor = g_dsn.getDesign();if (id == “design” || item.userObj.istabpage || !editor.isVisible()) {
this.menu.deleteitem.setVisible(false);
} else {
this.menu.deleteitem.setVisible(true); this.menu.deleteitem.setOnClick(this.deleteWidget.bind(this, item));
}
// if(!item.iscon){
// this.menu.refreshitem.setVisible(false);
// }else{
// this.menu.refreshitem.setVisible(true);
// this.menu.refreshitem.setOnClick(this.refresh.bind(this, item, false));
// }
this.menu.popupAtCursor(e);
};
CoolOutlinePanel.ICONS = {
“chtmlwidget” : “ebi/user/coolrptdsn/images/widget/inner.png”,
“cwidgetgrid” : “ebi/user/reportpagedsn/images/tplgrid.png”
};
/**
- 报表模板的资源树,是一颗动态树,采用actontree设置action 即可,后台形成此树内容
* - @param wnd
- @param parentElement
- @param width
- @param height
- @param xmlconfig
*/
function CoolSourcePanel(wnd, parentElement, width, height) {
if (_biInPrototype)
this.xTree = new XTree(wnd, parentElement, width, height);return;
}
/**
初始化资源树
/
CoolSourcePanel.prototype.init = function() {
this.xTree.setOnExpand(this._getChildNode.bind(this));
this.xTree.getRootItem() .loadFrom( [ { // caption : "维表", caption : I18N .getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.14", "维表"), img0 : "ebi/images/lefttree/codemgr.gif", userObj : { id : "EBI$5$" + g_dwSubjectSet.getOwnerGroupId() }, haschild : true }, { caption : g_dwSubjectSet.getCaption(), img0 : "ebi/images/lefttree/tsk.gif", userObj : { id : g_dwSubjectSet.getResourceId() }, haschild : true } ]);
/**
- 添加数据源的节点
*/
this.datasourceTree = this.xTree
this.datasourceTree.id = “datasource”;.getRootItem() .appendChild( I18N .getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.15", "自定义数据源"));
this.datasourceTree
/*.setItemImage("ebi/user/reportpagedsn/images/datasource.gif");
- ISSUE:ESENBI-3946 add by RX 2015.01.09
没有执行SQL数据源的权限的用户查看或编辑表样时,不能让其看到新增和编辑sql数据源的权限,否则可能泄露数据信息,认为数据是有价值、高敏感的
*/
// this.datasourceTree.setVisible(g_showsql);
this.sqlds = this.datasourceTree.appendChild(I18N.getString("ebi.user.report.pagedsn.template.rpt_reporttemplate.js.16", "sql数据源"));
this.sqlds.id = “sqlroot”;
this.sqlds.setItemImage(“ebi/user/reportpagedsn/images/sqlds.gif”);this.oltpds = this.datasourceTree.appendChild(I18N.getString(
"ebi.user.report.pagedsn.template.rpt_reporttemplate.js.17", "oltp数据源"));
this.oltpds.id = “oltproot”;
this.oltpds.setItemImage(“ebi/user/reportpagedsn/images/oltpds.gif”);
// ESENBI-235, add by zqj 2014.12.04 oltp数据源功能前台界面隐藏掉
this.oltpds.setVisible(false);this.aliasds = this.datasourceTree.appendChild(I18N.getString(
"ebi.user.report.pagedsn.template.rpt_reporttemplate.js.18", "引用主题表"));
this.aliasds.id = “aliasftroot”;
this.aliasds.setItemImage(“ebi/user/reportpagedsn/images/aliasds.gif”);// 给数据源的树添加右键菜单
var self = this;
this.xTree.setOnContextMenu(function(item, e, obj) {
self.__oncontextMenuResourceTree(item, e, obj);
});this.xTree.setOnDblClick(function(item, e) {
self.__onDblClick(item, e);
});// 绑定拖拽事件
this.bindEvent();
};
- 添加数据源的节点
CoolSourcePanel.prototype.bindEvent = function() {
this._onmousedown = this.onDragSatrt.bind(this);
addEvent(this.xTree.treeDiv, “mousedown”, this._onmousedown, false);
};
/**
- 绑定拖拽事件
* - @param evt
*/
CoolSourcePanel.prototype.onDragSatrt = function(evt) {
var designobj = g_dsn.getDesign();
if (designobj && designobj.isVisible()) {
}designobj.dragStart(evt); return;
var getdataobj = g_dsn.getGetData();
if (getdataobj && getdataobj.isVisible()) {
}getdataobj.dragStart(evt); return;
};
/**
- 根据dom获得item
*/
CoolSourcePanel.prototype.getItemByDom = function(dom) {
var item = undefined, id;
for ( var i = 0; i < 5; i++) {
}id = dom.getAttribute("id"); if (id) { item = this.xTree.getItemObj(id); if (item) break; } dom = dom.parentNode;
return item;
};
/**
- 获得资源树
*/
CoolSourcePanel.prototype.getResourceTree = function() {
return this.xTree;
};
/**
- 左边栏数据源树上添加右键菜单
* - @param item
- @param e
@param obj
*/
CoolSourcePanel.prototype.__oncontextMenuResourceTree = function(item, e, obj) {
if (!item)return;
var self = this;
this.toolMenu = new XPopupMenu(this.wnd);
if (item.getParentItem().id == “datasource”) {// 自定义数据源下面几个节点,右键存在“新建”菜单 // this.toolMenu_newdef = // this.toolMenu.addXMenuItem("新建",null,function(){ this.toolMenu_newdef = this.toolMenu.addXMenuItem(I18N.getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.19", "新建"), null, function() { if (item.id == "sqlroot") { self.showSqlEditor(item, 0); } else if (item.id == "oltproot") { self.showOltpEditor(item, 0); } else if (item.id == "aliasftroot") { self.showAliasEditor(item, 0); } });
} else if (item.type == “sql” || item.type == “oltp”
|| item.type == "aliasft") { // 数据源下面的子节点存在“编辑”“删除”菜单 // this.toolMenu_newgroup = // this.toolMenu.addXMenuItem("编辑",null,function(){ this.toolMenu_newgroup = this.toolMenu.addXMenuItem(I18N.getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.20", "编辑"), null, function() { if (item.type == "sql") { self.showSqlEditor(item, 1); } else if (item.type == "oltp") { self.showOltpEditor(item, 1); } else if (item.type == "aliasft") { self.showAliasEditor(item, 1); } }); // this.toolMenu_deldef = // this.toolMenu.addXMenuItem("删除",null,function(){self.deleteDataSource(item);}); this.toolMenu_deldef = this.toolMenu.addXMenuItem(I18N.getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.21", "删除"), null, function() { self.deleteDataSource(item); }); // 如果是sql数据源添加设置属性的对话框 if (item.type == "sql") { // this.toolMenu_attrdef = // this.toolMenu.addXMenuItem("属性",null,function(){self.showAttrDlg(item);}); this.toolMenu_attrdef = this.toolMenu .addXMenuItem( I18N .getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.22", "属性"), null, function() { self.showAttrDlg(item); }); }
} else if (item.type == “sqlColunm”) {
// sql数据源的字段节点上绑定右键设置维表的菜单 // this.toolMenu_dimdef = // this.toolMenu.addXMenuItem("设置维表",null,function(){self.showDimsDlg(item);}); this.toolMenu_dimdef = this.toolMenu.addXMenuItem(I18N.getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.23", "设置维表"), null, function() { self.showDimsDlg(item); });
}
if (item.getParentItem().id == “ztdatasource”) {
// 自定义数据源下面几个节点,右键存在“新建”菜单 // this.toolMenu_newdef = // this.toolMenu.addXMenuItem("新建",null,function(){ this.toolMenu_newdef = this.toolMenu.addXMenuItem(I18N.getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.19", "新建"), null, function() { if (item.id == "bbq") { self.showSqlEditor(item, 0); } else if (item.id == "filter") { self.showOltpEditor(item, 0); } });
} else if (item.type == “filter” || item.type == “bbq”) {
// 数据源下面的子节点存在“编辑”“删除”菜单 // this.toolMenu_newgroup = // this.toolMenu.addXMenuItem("编辑",null,function(){ this.toolMenu_newgroup = this.toolMenu.addXMenuItem(I18N.getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.20", "编辑"), null, function() { if (item.getParentItem().id == "bbq") { self.showSqlEditor(item, 1); } else if (item.getParentItem().id == "filter") { self.showOltpEditor(item, 1); } }); // this.toolMenu_deldef = // this.toolMenu.addXMenuItem("删除",null,function(){self.deleteDataSource(item);}); this.toolMenu_deldef = this.toolMenu.addXMenuItem(I18N.getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.21", "删除"), null, function() { self.deleteDataSource(item); });
}
this.toolMenu.popupAtCursor(e);
};
/**
- 初始化自定义数据源的节点
* @param item
*/
CoolSourcePanel.prototype.fromJsonToDs = function(json) {
for ( var elem in json) {var data = {}; data[elem] = json[elem]; if (json[elem].tagname == "sql") { var obj = this.sqlds.appendChild(elem); obj.setUserObj(data); obj.name = elem; obj.type = "sql"; obj.setItemImage("ebi/user/reportpagedsn/images/sql.gif"); // 添加列的子节点 this.appendSqlColunm(json[elem].sqlcolunm, obj); } else if (json[elem].tagname == "oltp") { var obj = this.oltpds.appendChild(elem); obj.setUserObj(data); obj.name = elem; obj.type = "oltp"; obj.setItemImage("ebi/user/reportpagedsn/images/olap.gif"); } else if (json[elem].tagname == "factTableAlias") { var obj = this.aliasds.appendChild(elem); obj.setUserObj(data); obj.name = elem; obj.type = "aliasft"; obj.setItemImage("ebi/user/reportpagedsn/images/alias.gif"); }
}
};
/**
- 根据主题表的资源id在分析表中查找它的别名,如果该主题表不是它的引用主题表则返回null。
* - @param id
*/
CoolSourcePanel.prototype.getFactTableAliasName = function(id) {
// ESENBI-1774 add by zqj 2014.09.11 getName方法不支持,
// 因前段时间改分析组件的sql数据源时改过结构而引起的这个问题
var aliasarr = this.aliasds.getAllChildItem();
for ( var i = 0; i < aliasarr.length; i++) {
}var obj = aliasarr[i].getUserObj(); var name = aliasarr[i].name; var resourceid = obj[name].factTableAliasContent.resourceid; /** * resourceid有两种格式,可能是后面带.fact也可能不带,所以为了判断的更准确先将判断的字符串 * 用点分割成数组,然后比较第一个元素是否相等 add by mxm at 20100708 */ if (id.split('.')[0] == resourceid.split('.')[0]) { return name; }
return null;
};
/**
- 当操作数据源后,设置界面的状态为修改状态 ESENBI-1207 操作数据源后关闭时没有提示已修改的信息 add by zqj 2014.08.05
*/
CoolSourcePanel.prototype.setChangedState = function() {
var editor = g_dsn.getDesign();
if (!editor.hasChanged)
};editor.hasChanged = true;
/**
- 数据源的删除操作
* - @param item
*/
CoolSourcePanel.prototype.deleteDataSource = function(item) {
var self = this;
// confirmDialog(“提示”,”确定删除?”, false, null, function() {
confirmDialog(
};I18N .getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.12", "提示"), I18N .getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.24", "确定删除?"), false, null, function() { item.remove(); // 设置界面为修改状态 self.setChangedState(); });
/**
- sql数据源定义框
* - @param item
- 父节点
- @param status
- 0-新建 1-编辑
*/
CoolSourcePanel.prototype.showSqlEditor = function(item, status) {
var self = this;
// ESENBI-252,编辑后关闭一张表,打开另一张表在编辑没反应
getObjectFromRootAsync(“OltpSqlEditor”, “_SqlDlg_Imp”, true,
“xdialog,ebi/user/reportpagedsn/dlg/sqleditor.js”, function(dlg) {
dlg.setOnOk(function(v) {
});self.onSqlFinish(v, item);
if (status == 1) {
} else {// 编辑,加载内容 dlg.loadFromObj(item.getUserObj(), null);
}// 新建,初始化名称 dlg.loadFromObj(null, self._getUniqueDataSourceName("rs")); // 新建时,设置默认的连接池是主题集的默认连接池 // ESENBI-2045 add by zqj 2014.10.10 dlg.setSqlDataSource(g_dwSubjectSet.getResourceId());
dlg.open(true);
});
};
/*
- 将之前设置的SQL源额外属性(关联维表、关联特殊字段等)合并到新的树节点自定义对象上 合并策略是如果相同名字的字段仍存在,则保留到新对象上
- newUserObj和userObj是树节点上依附的对象,具体内容格式见sqltableset.js#export2obj及sqleditor.js#SqlResultSet&jsonToSqlRs
- sqldsName为正在编辑的SQL数据源名字
*/
CoolSourcePanel.prototype._mergeSqlAdditionalSetting = function(newUserObj,
if (!userObj) {userObj, sqldsName) {
}return;
var newSqlJson = newUserObj[sqldsName];
// 新的SQL列列表,是老设置中关联字段是否需要保留的参考依据
var newSqlColumns = newSqlJson[“sqlcolunm”];
var newColumnArr = newSqlColumns.split(“;”);
var newColumnsObj = {};
var newcolnum = newColumnArr.length;
for ( var i = 0; i < newcolnum; i++) {
}var acol = newColumnArr[i]; if (!!acol) { newColumnsObj[acol] = true; }
var sqlJson = userObj[sqldsName];
if (!sqlJson)
if (!!sqlJson[“option”]) {return;
}var option = sqlJson.option; var newoption = {}; var mid = option["mid"]; if (!!mid && newColumnsObj[mid]) { newoption["mid"] = mid; } var pid = option["pid"]; if (!!pid && newColumnsObj[pid]) { newoption["pid"] = pid; } var bbqfield = option["bbqfield"]; if (!!bbqfield && newColumnsObj[bbqfield]) { newoption["bbqfield"] = bbqfield; } var frombbq = option["frombbq"]; if (!!frombbq && newColumnsObj[frombbq]) { newoption["frombbq"] = frombbq; } var tobbq = option["tobbq"]; if (!!tobbq && newColumnsObj[tobbq]) { newoption["tobbq"] = tobbq; } if (!isEmptyJson(newoption)) { if (!!newoption["bbqfield"] || !!newoption["frombbq"] || !!newoption["tobbq"]) { newoption["bbqkind"] = option["bbqkind"]; newoption["bbqtype"] = option["bbqtype"]; } newoption["mid"] = newoption["mid"] || ""; newoption["pid"] = newoption["pid"] || ""; newSqlJson["option"] = newoption; }
if (!!sqlJson[“dimcolunm”]) {
}var dimcolumn = sqlJson.dimcolunm; var newdimcolsObj = {}; for ( var col in dimcolumn) { var dim = dimcolumn[col]; if (!!dim && newColumnsObj[col]) { newdimcolsObj[col] = dim; } } if (!isEmptyJson(newdimcolsObj)) { newSqlJson["dimcolunm"] = newdimcolsObj; }
};
/**
- sql数据源定义框按“确定”按钮后的处理
* - @param v
- obj对象,包含name,json,colunm字段
- @param item
树节点
*/
CoolSourcePanel.prototype.onSqlFinish = function(v, item) {// 设置界面为修改状态
this.setChangedState();// 判断是新建还是编辑
var obj;
// 将SQL数据源树节点原来绑定的对象备份起来,供后面合并属性使用
var bkUserObj = item.getUserObj();
if (!item.type) { // 新建
// 判断是否重名
if (this._equalDataSourceName(v.name)) {
showMessage(I18N.getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.25", "存在同名的数据源!"));
return;
}
obj = item.appendChild(v.name);
} else {// 编辑
obj = item;
// 判断是否重名
if (obj.name != v.name) {
if (this._equalDataSourceName(v.name)) {
showMessage(I18N.getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.25", "存在同名的数据源!"));
return;
}
}
// 判断编辑是否有改动,数据源名和sql语句和连接池都没有改动,则不需要重新加载字段子节点
// 需要比较字节点是否一样,不一样仍需重新加载
if ((obj.name == v.name)) {
var startObj = item.getUserObj()[obj.name];
var startSql = startObj[“sqlcontent”].trim();
var startdb = startObj[“dbserver”];
var startcolunm = startObj[“sqlcolunm”];
var endObj = v.toJson;
var endSql = endObj[“sqlcontent”].trim();
var enddb = endObj[“dbserver”];
var endcolunm = endObj[“sqlcolunm”];
if (startSql == endSql&& startdb == enddb && compareJson(startObj["macros"] || {}, endObj["macros"] || {}) && startcolunm == endcolunm) {
return;
}
}
obj.setItemText(v.name);
obj.clearChildren();
}
// 在树上更新节点
var userObj = {};
userObj[v.name] = v.toJson;
obj.setUserObj(userObj);
obj.name = v.name;
obj.type = “sql”;
obj.setItemImage(“ebi/user/reportpagedsn/images/sql.gif”);
// 从原设置中的option/dimcolunm合并仍存在的字段设置
this._mergeSqlAdditionalSetting(userObj, bkUserObj, v.name);// 解析sql语句,更新节点
this.appendSqlColunm(v.colunm, obj);
};
/**
- 给sql数据源添加列的子节点
* - @param colunms
- @param item
*/
CoolSourcePanel.prototype.appendSqlColunm = function(colunms, item) {
var colunm = colunms.split(“;”);
var userObj = item.getUserObj();
var name = item.name;
var dimcolunm = userObj[name].dimcolunm;
for ( var i = 0; i < colunm.length; i++) {
}var child = colunm[i]; if (child != "" && child != "") { var colobj = item.appendChild(child); colobj.colunm = child; colobj.name = item.name; colobj.type = "sqlColunm"; if (dimcolunm && dimcolunm[child]) { colobj.setItemText(child + "-->" + dimcolunm[child]); colobj.dimname = dimcolunm[child]; } this.appendSqlColunmEvent(colobj); }
item.setExpanded(false);
};
/**
- sql数据源在树上添加指标拖拽事件
* - @param item
*/
CoolSourcePanel.prototype.appendSqlColunmEvent = function(item) {
var dragDom = item.getItemDom().parentNode.firstChild;
var dragparam = {
};sqldim : item.name + "." + item.colunm
dragDom.setAttribute(“dragtype”, “ds_sqldim”);
dragDom.setAttribute(“dragparam”, JSON.stringify(dragparam));
item.nodeTable.setAttribute(“id”, dragparam[“sqldim”]);
item.id = dragparam[“sqldim”];
};
/**
- sql数据源右键属性的方法 弹出设置属性的对话框
* @param item
*/
CoolSourcePanel.prototype.showAttrDlg = function(item) {
var obj = item.getUserObj();
var name = item.name;
var self = this;
// ESENBI-3998 add by zqj 2015.01.07
// sql数据源的属性框和主题集属性中的数据表映射对话框都是全局的对话框,不同的js对象实现的,之前两个id重复了,导致一个打开后,另一个就报错
getObjectFromRootAsync(“OltpThemeDlg”, “__SqlPro”, true,"xui/ctrls/xcombobox.js,ebi/user/reportpagedsn/dlg/sqltableset.js", function(otd) { otd.loadFrom(obj[name].option); otd.loadColunms(obj[name].sqlcolunm); otd.setIconStyle("window-titleicon_edit"); otd.setOnOk(function(option) { // 将设置的属性值存储到左树上 obj[name].option = option; item.setUserObj(obj); // 设置界面为修改状态 self.setChangedState(); }); otd.open(true); });
};
/**
- sql数据源字段节点上的右键设置维表的方法 弹出维表选择下拉框
* @param item
*/
CoolSourcePanel.prototype.showDimsDlg = function(item) {var self = this;
getObjectFromRootAsync(“ShowDimsDlg”, “_ShowDimsDlgPro”, true,"ebi/user/reportpagedsn/dlg/sqltableset.js", function(otd) { // 获得维表数据,及初始化值,进行设置 var dnm = item.dimname; g_dwSubjectSet.dimsMgr = null; g_dwSubjectSet.getTaskDims(function(dims) { otd.setDims(dims, dnm); }); // 设置确定后的回调函数,修改树上显示的文字,将设置的维表存储起来 otd.setOnOk(function(dimName) { // 将设置的对应维度绑定到树的节点上 var caption = item.colunm; if (dnm == dimName) return; item.setItemText(dimName ? (caption + "-->" + dimName) : caption); item.dimname = dimName; // 更新父节点存储的json格式 var pitem = item.getParentItem(); var userObj = pitem.getUserObj(); var name = item.name; var dimcolunm = userObj[name].dimcolunm; if (!dimcolunm) { dimcolunm = {}; } // 如果设置了维表,添加一个属性,如果清空维表,这将改属性清空 if (dimName) { dimcolunm[caption] = dimName; } else { if (dimcolunm[caption]) { delete dimcolunm[caption]; } } userObj[name].dimcolunm = dimcolunm; pitem.getUserObj(userObj); // 设置界面为修改状态 self.setChangedState(); }); // 打开对话框 otd.open(true); });
};
/**
- OLTP数据源定义框
* - @param item
- 父节点
- @param status
- 0-新建 1-编辑
*/
CoolSourcePanel.prototype.showOltpEditor = function(item, status) {
var self = this;
getObjectFromRootAsync(
“OltpThemeDlg”,
“_OltpDlg_Imp”,
true,
“ebi/user/reportpagedsn/dlg/oltpeditor.js”,
function(dlg) {
dlg.setOnOk(function(o) {
});self.onOltpFinish(o, item);
var theme = dlg.getOltpTheme();
theme.setVisibleDbLink(true);
theme.setThemeReadOnly(false);
if (status == 1) {
} else {// 编辑,加载内容 theme.loadFrom(item.getUserObj());
}// 新建,初始化名称 theme.loadFrom(null); theme.setOltpName(self._getUniqueDataSourceName("olt"));
theme
dlg.setThemeNameCaption(I18N .getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.48", "数据源名称:"));
dlg.open(true);.setCaption(I18N .getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.49", "OLTP数据源"));
});
};
/**
- OLTP数据源定义框 按“确定”按钮后的操作
* - @param v
- obj对象,包含name,json字段
- @param item
父节点
*/
CoolSourcePanel.prototype.onOltpFinish = function(v, item) {// 设置界面为修改状态
this.setChangedState();// 判断是新建还是编辑
var obj;
if (!item.type) { // 新建
// 判断是否重名
if (this._equalDataSourceName(v.name)) {
showMessage(I18N.getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.25", "存在同名的数据源!"));
return;
}
obj = item.appendChild(v.name);
} else {// 编辑
obj = item;
// 判断是否重名
if (obj.name != v.name) {
if (this._equalDataSourceName(v.name)) {
showMessage(I18N.getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.25", "存在同名的数据源!"));
return;
}
}
obj.setItemText(v.name);
obj.clearChildren();
}// 树上节点更新
var userObj = {};
userObj[v.name] = v.toJson;
obj.setUserObj(userObj);
obj.name = v.name;
obj.type = “oltp”;
obj.setItemImage(“ebi/user/reportpagedsn/images/oltp.gif”);
};
/**
- 引用主题表定义框
* - @param item
- 父节点
- @param status
- 0-新建 1-编辑
*/
CoolSourcePanel.prototype.showAliasEditor = function(item, status) {
var self = this;
getObjectFromRootAsync(“AliasFTEditor”, “_AliasFTDlg_Imp”, true,
“xdialog,ebi/user/reportpagedsn/dlg/aliasfteditor.js”,
function(dlg) {
dlg.setTaskid(g_dwSubjectSet.getTaskId());
if (status == 1) {
} else {// 编辑,加载内容 dlg.loadJson(item.getUserObj());
}// 新建,初始化名称 dlg.setAliasName(self._getUniqueDataSourceName("aft"));
dlg.onClickOk = function(v) {
};if (dlg.clickOK()) { self.onAliasFinish(v, item); }
dlg.show();
});
};
/**
- 引用主题表定义框 按“确定”按钮后的操作
* - @param v
- obj对象,包含name,json字段
- @param item
父节点
*/
CoolSourcePanel.prototype.onAliasFinish = function(v, item) {// 设置界面为修改状态
this.setChangedState();// 判断是新建还是编辑
var obj;
if (!item.type) { // 新建
// 判断是否重名
if (this._equalDataSourceName(v.name)) {
showMessage(I18N.getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.25", "存在同名的数据源!"));
return;
}
obj = item.appendChild(v.name);
} else {// 编辑
obj = item;
// 判断是否重名
if (obj.name != v.name) {
if (this._equalDataSourceName(v.name)) {
showMessage(I18N.getString( "ebi.user.report.pagedsn.template.rpt_reporttemplate.js.25", "存在同名的数据源!"));
return;
}
}
obj.setItemText(v.name);
obj.clearChildren();
}// 在树上更新节点
var userObj = {};
userObj[v.name] = v.toJson;
obj.setUserObj(userObj);
obj.name = v.name;
obj.type = “aliasft”;
obj.setItemImage(“ebi/user/reportpagedsn/images/alias.gif”);
};
/**
双击事件 sql和oltp双击打开编辑界面 引用主题表,在bottomworkspace中打开主题表
*/
CoolSourcePanel.prototype.__onDblClick = function(item, e) {if (item.type == “sql”) {
this.showSqlEditor(item, 1);
} else if (item.type == “oltp”) {
this.showOltpEditor(item, 1);
} else if (item.type == “aliasft”) {
var json = item.getUserObj(); var name = item.name; var rptid = json[name].factTableAliasContent.resourceid; if (rptid) { var ws = getWorkspace(); /** * ISSUE:http://192.168.1.200/jira/browse/WTAP-1119 * 调用了setCellContentStyle("pickname")后处于拾取状态才会显示字段名 */ if (ws) { ws.showTaskbook(rptid, null, function(wnd) { wnd.taskbook.setCellContentStyle("pickname"); }, null, g_dsn.getAsidePlaceInWorkspace()); } }
}
};
/**
- 清空数据源,在装入本地文件前要清空数据源的树 ESENBI-1693 add by zqj 2014.09.10
*/
CoolSourcePanel.prototype.clearDataSource = function() {
this.sqlds.clearChildren();
this.oltpds.clearChildren();
this.aliasds.clearChildren();
};
/**
获得数据源树上的自定义数据源的json格式
*/
CoolSourcePanel.prototype.getDataSource = function() {
var datasourceJson = {};
// sql数据源
var sqlarr = this.sqlds.getAllChildItem();
for ( var i = 0; i < sqlarr.length; i++) {var item = sqlarr[i]; $.extend(datasourceJson, item.getUserObj());
}
// oltp数据源
var oltparr = this.oltpds.getAllChildItem();
for ( var i = 0; i < oltparr.length; i++) {var item = oltparr[i]; $.extend(datasourceJson, item.getUserObj());
}
// 主题表数据源
var aliasarr = this.aliasds.getAllChildItem();
for ( var i = 0; i < aliasarr.length; i++) {var item = aliasarr[i]; $.extend(datasourceJson, item.getUserObj());
}
return datasourceJson;
};
/**
- 根据数据源的名字,获得数据源信息 表格中的打点提示信息会使用到,需要根据数据源的名字,获得相应的字段 add by zqj 2015.02.10
* @param name
*/
CoolSourcePanel.prototype.getDataSourceByName = function(name) {
var datasourceJson = null;// 获得数据源数组
var sqlarr = this.sqlds.getAllChildItem();
var oltparr = this.oltpds.getAllChildItem();
var aliasarr = this.aliasds.getAllChildItem();
var arr = [];
arr.putAll(sqlarr);
arr.putAll(oltparr);
arr.putAll(aliasarr);// 循环数组,查找数据源
for ( var i = 0; i < arr.length; i++) {var item = arr[i]; if (name.equalsIgnoreCase(item.name)) { datasourceJson = item.getUserObj(); break; }
}
return datasourceJson;
};
/**
- 判断数据源名字是否重名
* - @param name
- 需要判断的数据源名字
- @returns {Boolean} 重名返回true
*/
CoolSourcePanel.prototype._equalDataSourceName = function(name) {
var datasourceName = this.getDataSourceName();
if (datasourceName) {
}var p = datasourceName.toUpperCase(); var m = name.toUpperCase(); return (p == m) || p.startsWith(m + ",") || p.endsWith("," + m) || (p.indexOf("," + m + ",") > -1);
return false;
};
/**
- 获取某数据源的唯一名称,用于新建的时候初始化到数据源编辑框中 tag 名称前缀 rs olt aft return 名字
*/
CoolSourcePanel.prototype._getUniqueDataSourceName = function(tag) {
var i = 1;
var nm = “”;
while (i < 200) {// 防止死循环
}nm = tag + i; if (!this._equalDataSourceName(nm)) { break; } i++;
return nm;
};
/**
- 获得数据源的名字,用,分割
* @returns {String}
*/
CoolSourcePanel.prototype.getDataSourceName = function() {
var name = “”;
// sql数据源
var sqlarr = this.sqlds.getAllChildItem();
for ( var i = 0; i < sqlarr.length; i++) {name += sqlarr[i].name + ",";
}
// oltp数据源
var oltparr = this.oltpds.getAllChildItem();
for ( var i = 0; i < oltparr.length; i++) {name += oltparr[i].name + ",";
}
// 主题表数据源
var aliasarr = this.aliasds.getAllChildItem();
for ( var i = 0; i < aliasarr.length; i++) {name += aliasarr[i].name + ",";
}
// 获得主题表名称
if (!this.factTableFlag) {this.getFactTableName();
}
if (this.factTableName) {name += this.factTableName;
}
return name;
};
/**
- 获取指定类型的数据源名称,多个数据源名称用逗号分隔
* - @param dstype
- 数据源类型,sql/oltp/olap/facts等
*/
CoolSourcePanel.prototype.getDataSourceNames = function(dstype) {
if (!dstype)
return this.getDataSourceName();
var dstypeL = dstype.toLowerCase();
var dsname = “”;
if (“sql” === dstypeL) {
// sql数据源
var sqlarr = this.sqlds.getAllChildItem();
for ( var i = 0; i < sqlarr.length; i++) {
dsname += sqlarr[i].name + “,”;
}
} else if (“oltp” == dstypeL) {
// oltp数据源
var oltparr = this.oltpds.getAllChildItem();
for ( var i = 0; i < oltparr.length; i++) {
dsname += oltparr[i].name + “,”;
}
} else if (“facts” == dstypeL) {
// 主题表数据源
var aliasarr = this.aliasds.getAllChildItem();
for ( var i = 0; i < aliasarr.length; i++) {
dsname += aliasarr[i].name + “,”;
}
}
dsname = dsname.substring(0, dsname.length - 1);
return dsname;
};
/**
获得主题表名称 建数据源时使用,数据源名不能和主题表名相同
*/
CoolSourcePanel.prototype.getFactTableName = function() {
var name = “”;
var self = this;
var params = new Map();
var taskid = g_dwSubjectSet.getTaskId();
params.put(“rid”, “EBI$11$” + taskid + “$/“);
QueryObj.create(“/panelrestree.do”, params, function(query) {try { query.checkResult(); if (query.isResultOk()) { var result = query.getResponseJSON(); for ( var i = 0; i < result.length; i++) { var data = result[i]; name += data.caption.split(" ")[0] + ","; } self.factTableName = name; self.factTableFlag = true; } } catch (e) { showError(e); }
});
};
/**
- 展开时请求服务器获取子节点
* - @param item
*/
CoolSourcePanel.prototype._getChildNode = function(item) {
if (item.getChildrenCount() != 0) {
}return;
var self = this;
var params = new Map();
params.put(“rid”, item.getUserObj().id);
QueryObj.create(“/panelrestree.do”, params, function(query) {
});try { query.checkResult(); if (query.isResultOk()) { var result = query.getResponseJSON(); item.loadFrom(result, self._onLoadFinish.bind(self)); } } catch (e) { showError(e); }
};
/**
- 展开后对节点的处理
* - @param item
*/
CoolSourcePanel.prototype._onLoadFinish = function(item) {
var dragtype = item.userObj.dragtype;
if (dragtype) {
}var dragDom = item.getItemDom().parentNode.firstChild; var nodetable = item.nodeTable; var id = undefined; if (dragtype == "ds_zb") { var dragparam = { zb : item.getParentItem().itemText.split(" ")[0] + "." + item.itemText.split(" ")[0], userObj : item.userObj }; dragDom.setAttribute("dragtype", dragtype); dragDom.setAttribute("dragparam", JSON.stringify(dragparam)); id = dragparam["zb"]; } else if (dragtype == "ds_dim") { var dragparam = { name : item.userObj.dimname ? item.userObj.dimname : item .getParentItem().itemText, level : item.userObj.level, userObj : item.userObj }; dragDom.setAttribute("dragtype", dragtype); dragDom.setAttribute("dragparam", JSON.stringify(dragparam)); id = (item.userObj["id"] || item.getParentItem().id) + (dragparam["level"] || ""); } if (id) { nodetable.setAttribute("id", id); item.id = id; }
};
CoolWidgetPanel.prototype.onHover = function(evt) {
var target = evt.target, id = target.id, cls = target.className;
var htmlWidgetPanel = this.htmlWidgetPanel;
evt.preventDefault();
evt.stopPropagation();
htmlWidgetPanel.cmd_previewHtmlWidgetForSave(evt);// 鼠标悬浮图片用
/*- var design = g_dsn.getDesign(); if(design && design.isVisible()){
- design.dragStart(evt); }
*/
};
/**
鼠标悬浮html组件图片专用
*/
CoolHTMLWidgetSubPanel.prototype.cmd_previewHtmlWidgetForSave = function(e) {
if (!this.previewpanel) {this.previewpanel = $( "<div class='preview_panel'><iframe frameborder='0' width='100%', height='100%'></iframe></div>") .appendTo(this.doc.body)[0];
}
var body = this.panel.getContentDom();
this.previewpanel.style.cssText += “;left:” + (body.offsetWidth + 2)+ "px;display:block;";
var widgetPath = e.target;
if (widgetPath.nodeName == “SPAN” && widgetPath.getAttribute(“dragparam”)) {widgetPath = getXComponentByDom(e.target).id;
} else {
this.previewpanel.style.display = "none"; return false;
}
var wigId = widgetPath;
this.checkPosition(e);
var date = (new Date()).getTime();
// ?”+date+”
var self = this;
if (self.previewpanel) {self.previewpanel.style.display = "none";
}
this._timer = setTimeout(function() { self.previewpanel.style.display = "block"; var imgPath = "vfs" + self.typepath + "coolwidgetimg/" + wigId + ".png"; if (self._timestamp) { imgPath += "?" + self._timestamp + ""; } self.previewpanel.innerHTML = "<img src='" + imgPath + "' " + "style='display: inline-block;height: auto;max-width: 100%;max-height: 100%;' />"; $(self.previewpanel).addClass('preview_images'); }, 1000);
return false;
};
/**
重新加载(刷新)
*/
CoolHTMLWidgetSubPanel.prototype.cmd_reload = function(item) {
var self = this;
var map = new Map();
map.put(“action”, “reload”);
map.put(“basepath”, this.typepath);
QueryObj.create(CoolHTMLWidgetSubPanel.ACTION_URL, map, function(query) {try { query.checkResult(); if (query.isResultOk()) { // 刷新内置组件 var sysItem = self.getSysRootItem(); sysItem.clearChildren(); sysItem._loaded = false; self._onExpandTreeItem(sysItem); // 刷新自定义组件 var usrItem = self.getUserRootItem(); usrItem.clearChildren(); usrItem._loaded = false; self._onExpandTreeItem(usrItem); self._timestamp = (new Date()).getTime();// 记录刷新的时间戳,悬浮图片专用 } } catch (e) { showError(e); }
});
};
/**
- 检查鼠标位置,悬浮图片用
/
CoolHTMLWidgetSubPanel.prototype.checkPosition = function(e) {
var parentHeight = this.previewpanel.parentElement.offsetHeight;
if ((parentHeight 0.5 + getCursorPosition(e, this.wnd).y) > parentHeight) {
} else {this.previewpanel.style.top = "auto"; this.previewpanel.style.cssText += ";bottom:" + 3 + "px;left:" + (this.panel.getContentDom().offsetWidth + 2) + "px;display:block;";
}this.previewpanel.style.cssText += ";top:" + getCursorPosition(e, this.wnd).y + "px;left:" + (this.panel.getContentDom().offsetWidth + 2) + "px;display:block;";
};
/** - 判断请求的图片资源是否存在
*/
CoolHTMLWidgetSubPanel.prototype.CheckImgExists = function(imgurl) {
var ImgObj = new Image(); // 判断图片是否存在
ImgObj.src = imgurl;
// 没有图片,则返回-1
if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
} else {return true;
}return false;
}
/** - 销毁方法
*/
CoolSourcePanel.prototype.dispose = function() {
this.xTree.dispose();
this.factTableName = null;
};