MWF.xApplication.cms = MWF.xApplication.cms || {}; //MWF.xApplication.cms.Column = MWF.xApplication.cms.Column || {}; MWF.xDesktop.requireApp("cms.Column", "Actions.RestActions", null, false); MWF.xApplication.cms.Column.Main = new Class({ Extends: MWF.xApplication.Common.Main, Implements: [Options, Events], options: { "style": "default", "name": "cms.Column", "icon": "icon.png", "width": "1000", "height": "600", "isResize": false, "isMax": true, "title": MWF.xApplication.cms.Column.LP.title, "tooltip": { "description": MWF.xApplication.cms.Column.LP.description, "column": { "title": MWF.xApplication.cms.Column.LP.column.title, "create": MWF.xApplication.cms.Column.LP.column.create, "nameLabel": MWF.xApplication.cms.Column.LP.column.nameLabel, "aliasLabel": MWF.xApplication.cms.Column.LP.column.aliasLabel, "descriptionLabel": MWF.xApplication.cms.Column.LP.column.descriptionLabel, "sortLabel": MWF.xApplication.cms.Column.LP.column.sortLabel, "iconLabel": MWF.xApplication.cms.Column.LP.column.iconLabel, "cancel": MWF.xApplication.cms.Column.LP.column.cancel, "ok": MWF.xApplication.cms.Column.LP.column.ok, "inputName": MWF.xApplication.cms.Column.LP.column.inputName, "create_cancel_title": MWF.xApplication.cms.Column.LP.column.create_cancel_title, "create_cancel": MWF.xApplication.cms.Column.LP.column.create_cancel, "noDescription": MWF.xApplication.cms.Column.LP.column.noDescription, "delete": MWF.xApplication.cms.Column.LP.column.delete, "edit": MWF.xApplication.cms.Column.LP.column.edit, "delete_confirm_content": MWF.xApplication.cms.Column.LP.column.delete_confirm_content, "delete_confirm_title": MWF.xApplication.cms.Column.LP.column.delete_confirm_title, "createColumnSuccess": MWF.xApplication.cms.Column.LP.column.createColumnSuccess, "updateColumnSuccess": MWF.xApplication.cms.Column.LP.column.updateColumnSuccess }, "category": { "title": MWF.xApplication.cms.Column.LP.category.title, "create": MWF.xApplication.cms.Column.LP.category.create, "nameLabel": MWF.xApplication.cms.Column.LP.category.nameLabel, "aliasLabel": MWF.xApplication.cms.Column.LP.category.aliasLabel, "descriptionLabel": MWF.xApplication.cms.Column.LP.category.descriptionLabel, "sortLabel": MWF.xApplication.cms.Column.LP.category.sortLabel, "iconLabel": MWF.xApplication.cms.Column.LP.category.iconLabel, "columnLabel": MWF.xApplication.cms.Column.LP.category.columnLabel, "cancel": MWF.xApplication.cms.Column.LP.category.cancel, "ok": MWF.xApplication.cms.Column.LP.category.ok, "inputName": MWF.xApplication.cms.Column.LP.category.inputName, "create_cancel_title": MWF.xApplication.cms.Column.LP.category.create_cancel_title, "create_cancel": MWF.xApplication.cms.Column.LP.category.create_cancel, "noDescription": MWF.xApplication.cms.Column.LP.category.noDescription, "edit": MWF.xApplication.cms.Column.LP.category.edit } } }, onQueryLoad: function () { this.lp = MWF.xApplication.cms.Column.LP; this.defaultColumnIcon = "/x_component_cms_Column/$Main/" + this.options.style + "/icon/column.png"; this.defaultCategoryIcon = "/x_component_cms_Column/$Main/" + this.options.style + "/icon/category2.png"; }, loadApplication: function (callback) { this.isAdmin = ( MWF.AC.isProcessPlatformCreator() || MWF.AC.isAdministrator() ); if (!this.restActions) this.restActions = new MWF.xApplication.cms.Column.Actions.RestActions(); this.columns = []; this.categorys = []; this.deleteElements = []; this.createNode(); this.loadApplicationContent(); if (callback) callback(); }, loadApplicationContent: function () { //this.loadToolbar(); this.loadColumnArea(); //this.loadCategoryArea(); }, createNode: function () { this.content.setStyle("overflow", "hidden"); this.node = new Element("div", { "styles": {"width": "100%", "height": "100%", "overflow": "hidden"} }).inject(this.content); }, loadToolbar: function () { this.toolbarAreaNode = new Element("div", { "styles": this.css.toolbarAreaNode, "text": this.options.tooltip.description }).inject(this.node); //this.createCreateAction(); //this.createSearchAction(); }, createCreateAction: function () { //if (MWF.AC.isProcessPlatformCreator()){ this.createCategoryNode = new Element("div", { "styles": this.css.createCategoryNode, "title": this.options.tooltip.category.create }).inject(this.toolbarAreaNode); this.createCategoryNode.addEvent("click", function () { this.createCategory(); }.bind(this)); //} }, loadColumnArea: function () { this.columnAreaNode = new Element("div", { "styles": this.css.columnAreaNode }).inject(this.node); this.columnToolbarAreaNode = new Element("div", { "styles": this.css.columnToolbarAreaNode }).inject(this.columnAreaNode); if (MWF.AC.isProcessPlatformCreator()) { if (MWF.AC.isAdministrator()) { this.createColumnNode = new Element("button", { "styles": this.css.createColumnNode, "text": this.options.tooltip.column.create }).inject(this.columnToolbarAreaNode); this.createColumnNode.addEvent("click", function () { this.createColumn(); }.bind(this)); } } this.columnToolbarTextNode = new Element("div", { "styles": this.css.columnToolbarTextNode, "text": this.options.tooltip.column.title }).inject(this.columnToolbarAreaNode); this.setColumnAreaSize(); this.addEvent("resize", this.setColumnAreaSize); this.loadColumnContentArea(); this.setColumnContentSize(); }, setColumnAreaSize: function () { var nodeSize = this.node.getSize(); var toolbarSize = this.columnToolbarAreaNode.getSize(); var y = nodeSize.y - toolbarSize.y; this.columnAreaNode.setStyle("height", "" + y + "px"); if (this.columnContentAreaNode) { var count = (nodeSize.x / 282).toInt(); var x = 282 * count; var m = (nodeSize.x - x) / 2 - 10; this.columnContentAreaNode.setStyles({ //"width": ""+x+"px", "margin-left": "" + m + "px" }); } }, setColumnContentSize: function () { var nodeSize = this.node.getSize(); if (this.columnContentAreaNode) { var count = (nodeSize.x / 282).toInt(); var x = 282 * count; var m = (nodeSize.x - x) / 2 - 10; this.columnContentAreaNode.setStyles({ //"width": ""+x+"px", "margin-left": "" + m + "px" }); } }, loadColumnContentArea: function () { this.columnContentAreaNode = new Element("div", { "styles": this.css.columnContentAreaNode }).inject(this.columnAreaNode); this.loadController(function () { this.createColumnNodes() }.bind(this)) //MWF.require("MWF.widget.DragScroll", function(){ // new MWF.widget.DragScroll(this.columnContentAreaNode); //}.bind(this)); MWF.require("MWF.widget.ScrollBar", function () { new MWF.widget.ScrollBar(this.columnContentAreaNode); }.bind(this)); }, loadController: function (callback) { this.availableApp = []; this.restActions.listControllerByPerson(layout.desktop.session.user.name, function (json) { if (json && json.data && json.data.length) { json.data.each(function (d) { //if( d.objectType == "APPINFO"){ this.availableApp.push(d.objectId) //} }.bind(this)) } if (callback)callback(); }.bind(this), null, true) }, hasPermision: function (appId) { return this.isAdmin || this.availableApp.contains(appId); }, createColumnNodes: function () { this.restActions.listColumn(function (json) { var emptyColumn = null; if (json && json.data && json.data.length) { var tmpArr = json.data; tmpArr.sort(function(a , b ){ return parseFloat( a.appInfoSeq ) - parseFloat(b.appInfoSeq); }) json.data = tmpArr; json.data.each(function (column) { if (this.hasPermision(column.id)) { var column = new MWF.xApplication.cms.Column.Column(this, column); column.load(); this.columns.push(column); } }.bind(this)); } if (this.columns.length == 0) { this.noElementNode = new Element("div", { "styles": this.css.noElementNode, "text": this.lp.column.noElement }).inject(this.columnContentAreaNode); } }.bind(this)); }, createColumn: function (text, alias, memo, icon, creator) { var column = new MWF.xApplication.cms.Column.Column(this); column.createColumn(this.node); }, /* createLoadding: function(){ this.loaddingNode = new Element("div", { "styles": this.css.noApplicationNode, "text": this.options.tooltip.loadding }).inject(this.applicationContentNode); }, removeLoadding: function(){ if (this.loaddingNode) this.loaddingNode.destroy(); }, */ }); MWF.xApplication.cms.Column.Column = new Class({ Implements: [Options, Events], options: { "where": "bottom" }, initialize: function (app, data, options) { this.setOptions(options); this.app = app; this.container = this.app.columnContentAreaNode; this.data = data; this.isNew = false; }, load: function () { this.data.name = this.data.appName; var columnName = this.data.appName; var alias = this.data.appAlias; var memo = this.data.description; var order = this.data.appInfoSeq; var creator = this.data.creatorUid; var createTime = this.data.createTime; //var icon = this.data.appIcon; //if( !icon || icon == "")icon = this.app.defaultColumnIcon; var itemNode = this.node = new Element("div.columnItem", { "styles": this.app.css.columnItemNode }).inject(this.container, this.options.where); itemNode.store("columnName", columnName); //itemNode.setStyle("background-color", this.options.bgColor[(Math.random()*10).toInt()]); var iconNode = this.iconNode = new Element("div", { "styles": this.app.css.columnItemIconNode }).inject(itemNode); //iconNode.setStyles({ // "background-image" : "url("+icon+")" //}); if (this.data.appIcon) { this.iconNode.setStyle("background-image", "url(data:image/png;base64," + this.data.appIcon + ")"); } else { this.iconNode.setStyle("background-image", "url(" + this.app.defaultColumnIcon + ")") } var textNode = new Element("div", { "styles": this.app.css.columnItemTextNode }).inject(itemNode) var titleNode = new Element("div", { "styles": this.app.css.columnItemTitleNode, "text": columnName, "title": (alias) ? columnName + " (" + alias + ") " : columnName }).inject(textNode) var description = ( memo && memo != "") ? memo : this.app.options.tooltip.column.noDescription; var descriptionNode = new Element("div", { "styles": this.app.css.columnItemDescriptionNode, "text": description, "title": description }).inject(textNode) var _self = this; itemNode.addEvents({ "mouseover": function () { if (!_self.selected) this.setStyles(_self.app.css.columnItemNode_over); }, "mouseout": function () { if (!_self.selected) this.setStyles(_self.app.css.columnItemNode); }, "click": function (e) { _self.clickColumnNode(_self, this, e) } }); if (MWF.AC.isProcessPlatformCreator()) { if ((creator == layout.desktop.session.user.name) || MWF.AC.isAdministrator()) { this.delAdctionNode = new Element("div.delNode", { "styles": this.app.css.columnItemDelActionNode, "title": this.app.options.tooltip.column.delete }).inject(itemNode); itemNode.addEvents({ "mouseover": function () { this.delAdctionNode.fade("in"); }.bind(this), "mouseout": function () { this.delAdctionNode.fade("out"); }.bind(this) }); this.delAdctionNode.addEvent("click", function (e) { this.deleteColumn(e); e.stopPropagation(); }.bind(this)); } } if (MWF.AC.isProcessPlatformCreator()) { if ((creator == layout.desktop.session.user.name) || MWF.AC.isAdministrator()) { this.editAdctionNode = new Element("div.editNode", { "styles": this.app.css.columnItemEditActionNode, "title": this.app.options.tooltip.column.edit }).inject(itemNode); itemNode.addEvents({ "mouseover": function () { this.editAdctionNode.fade("in"); }.bind(this), "mouseout": function () { this.editAdctionNode.fade("out"); }.bind(this) }); this.editAdctionNode.addEvent("click", function (e) { this.edit(e); e.stopPropagation(); }.bind(this)); } } }, clickColumnNode: function (_self, el, e) { /* _self.app.columns.each(function( column ){ if( column.selected ){ column.itemNode.setStyles( _self.app.css.columnItemNode ); } }) this.selected = true; el.setStyles( _self.app.css.columnItemNode_select ); */ var appId = "cms.ColumnManager" + this.data.id; if (this.app.desktop.apps[appId]) { this.app.desktop.apps[appId].setCurrent(); } else { this.app.desktop.openApplication(e, "cms.ColumnManager", { "column": this.data, "appId": appId, "onQueryLoad": function () { this.status = {"navi": 0}; } }); } }, checkDeleteColumn: function () { if (this.deleteElements.length) { if (!this.deleteElementsNode) { this.deleteElementsNode = new Element("div", { "styles": this.app.css.deleteElementsNode, "text": this.app.lp.column.deleteElements }).inject(this.node); this.deleteElementsNode.position({ relativeTo: this.container, position: "centerTop", edge: "centerbottom" }); this.deleteElementsNode.addEvent("click", function (e) { this.delete(); }.bind(this)); } } else { if (this.deleteElementsNode) { this.deleteElementsNode.destroy(); this.deleteElementsNode = null; delete this.deleteElementsNode; } } }, deleteColumn: function (e) { var _self = this; this.app.confirm("warn", e, this.app.options.tooltip.column.delete_confirm_title, this.app.options.tooltip.column.delete_confirm_content, "320px", "100px", function () { _self._deleteElement(); this.close(); }, function( ) { this.close(); } ) }, _deleteElement: function (id, success, failure) { this.app.restActions.removeColumn( id || this.data.id, function () { this.destroy(); if (success) success(); }.bind(this), function( error ){ var errorObj = JSON.parse( error.responseText ); this.app.notice(errorObj.message , "error"); if(failure)failure(); }.bind(this)); }, destroy: function () { this.node.destroy(); MWF.release(this); delete this; }, edit: function () { this.isNew = false; this.createContainer = this.app.node; this.createColumnCreateMarkNode(); this.createColumnCreateAreaNode(); this.createColumnCreateNode(); this.columnCreateAreaNode.inject(this.columnCreateMarkNode, "after"); this.columnCreateAreaNode.fade("in"); $("createColumnName").focus(); this.setColumnCreateNodeSize(); this.setColumnCreateNodeSizeFun = this.setColumnCreateNodeSize.bind(this); this.addEvent("resize", this.setColumnCreateNodeSizeFun); }, createColumn: function (container) { this.isNew = true; this.createContainer = container; this.createColumnCreateMarkNode(); this.createColumnCreateAreaNode(); this.createColumnCreateNode(); this.columnCreateAreaNode.inject(this.columnCreateMarkNode, "after"); this.columnCreateAreaNode.fade("in"); $("createColumnName").focus(); this.setColumnCreateNodeSize(); this.setColumnCreateNodeSizeFun = this.setColumnCreateNodeSize.bind(this); this.addEvent("resize", this.setColumnCreateNodeSizeFun); }, createColumnCreateMarkNode: function () { this.columnCreateMarkNode = new Element("div", { "styles": this.app.css.columnCreateMarkNode, "events": { "mouseover": function (e) { e.stopPropagation(); }, "mouseout": function (e) { e.stopPropagation(); } } }).inject(this.createContainer, "after"); }, createColumnCreateAreaNode: function () { this.columnCreateAreaNode = new Element("div", { "styles": this.app.css.columnCreateAreaNode }); }, createColumnCreateNode: function () { if (!this.isNew) { var columnName = this.data.appName; var alias = this.data.appAlias; var memo = this.data.description; var order = this.data.appInfoSeq; var creator = this.data.creatorUid; var createTime = this.data.createTime; //var icon = this.data.appIcon; //if( !icon || icon == "")icon = this.app.defaultColumnIcon; } else { var columnName = ""; var alias = ""; var memo = ""; var order = ""; var creator = ""; var icon = ""; var createTime = ""; } this.columnCreateNode = new Element("div", { "styles": this.app.css.columnCreateNode }).inject(this.columnCreateAreaNode); this.columnCreateNewNode = new Element("div", { "styles": ( this.isNew ? this.app.css.columnCreateNewNode : this.app.css.columnCreateEditNode ) }).inject(this.columnCreateNode); this.columnCreateFormNode = new Element("div", { "styles": this.app.css.columnCreateFormNode }).inject(this.columnCreateNode); var html = "
| " + this.app.options.tooltip.column.nameLabel + ": | " + "|
| " + this.app.options.tooltip.column.aliasLabel + ": | " + //"|
| " + this.app.options.tooltip.column.descriptionLabel + ": | " + "|
| " + this.app.options.tooltip.column.sortLabel + ": | " + "|
| " + this.app.options.tooltip.column.iconLabel + ": | " + "|
| "+this.options.tooltip.column.iconLabel+": | " + //"|
| "+this.options.tooltip.iconLabel+": | " + //"