123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- MWF.xApplication.process.ProcessDesigner.widget = MWF.xApplication.process.ProcessDesigner.widget || {};
- //MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.ScriptText",null,false);
- MWF.xApplication.process.ProcessDesigner.widget.ProjectionEditor = new Class({
- Implements: [Options, Events],
- Extends: MWF.widget.Common,
- options: {
- "style": "default",
- "maxTypeCount": {
- "string": 10,
- "long": 5,
- "double": 5,
- "boolean": 2,
- "date":2,
- "time": 2,
- "dateTime": 5
- }
- },
- initialize: function(node, text, options){
- this.setOptions(options);
- this.node = $(node);
- this.data = (text) ? JSON.decode(text) : [];
- this.name = node.get("name");
- this.path = "../x_component_process_ProcessDesigner/widget/$ProjectionEditor/";
- this.cssPath = "../x_component_process_ProcessDesigner/widget/$ProjectionEditor/"+this.options.style+"/css.wcss";
- this._loadCss();
- this.selectedItems = [];
- this.items = {};
- },
- getData: function(){
- return this.data;
- },
- load: function(){
- this.titleNode = this.node.getFirst("div").setStyles(this.css.titleNode).set("text", MWF.xApplication.process.ProcessDesigner.LP.projectionTitle);
- // this.titleNode = new Element("div", {"styles": this.css.titleNode}).inject(this.node);
- // this.titleNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.projectionTitle);
- this.tableArea = this.node.getLast("div");
- this.actionNode = this.tableArea.getPrevious().setStyles(this.css.actionNode).set("text", MWF.xApplication.process.ProcessDesigner.LP.projectionActionNode_add);
- var inputs = this.node.getElements("input");
- this.nameInput = inputs[0];
- this.pathInput = inputs[1];
- this.typeSelect = this.node.getElement("select");
- // this.tableArea = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.node);
- var html = "<table cellspacing='0' cellpadding='3px' width='100%' border='0'><tr>" +
- "<th>"+MWF.xApplication.process.ProcessDesigner.LP.projectionDataName+"</th>" +
- "<th>"+MWF.xApplication.process.ProcessDesigner.LP.projectionPath+"</th>" +
- "<th>"+MWF.xApplication.process.ProcessDesigner.LP.projectionType+"</th>" +
- "<th>"+MWF.xApplication.process.ProcessDesigner.LP.projectionName+"</th>" +
- "<th></th>" +
- "</tr></table>";
- this.tableArea.set("html", html);
- this.table = this.tableArea.getElement("table").setStyles(this.css.projectionTable);
- this.tableArea.getElements("th").setStyles(this.css.projectionTableTitle);
- this.runAction = new Element("div.mainColor_bg", {"styles": this.css.actionNode, "text": MWF.xApplication.process.ProcessDesigner.LP.projectionRunActionNode}).inject(this.node);
- this.loadProjectionList();
- // //this.loadProjectionCreate();
- //
- //
- // this.actionNode = new Element("div", {"styles": this.css.actionNode, "text": MWF.xApplication.process.ProcessDesigner.LP.projectionActionNode}).inject(this.node);
- this.actionNode.addEvent("click", this.changeProjectionItem.bind(this));
- this.runAction.addEvent("click", function(e){
- var _self = this;
- MWF.xDesktop.confirm("infor", e, MWF.xApplication.process.ProcessDesigner.LP.projectionRunTitle, MWF.xApplication.process.ProcessDesigner.LP.projectionRunText, 300, 120, function(){
- _self.runProjection();
- this.close();
- }, function(){
- this.close();
- }, null, null, "o2");
- }.bind(this));
- //
- // this.selectNode = new Element("div", {"styles": this.css.selectNode}).inject(this.node);
- //
- // this.downNode = new Element("div", {"styles": this.css.downNode}).inject(this.node);
- //
- // this.previewNode = new Element("div", {"styles": this.css.previewNode}).inject(this.node);
- // this.showNode = new Element("div", {"styles": this.css.showNode}).inject(this.node);
- //
- // this.propertyNode = new Element("div", {"styles": this.css.propertyNode}).inject(this.node);
- //
- // this.loadSelectNode();
- // this.loadSerialActivity();
- },
- runProjection: function(){
- o2.Actions.get("x_processplatform_assemble_designer").executeProjection(this.options.process, null, function(json){
- if (json.data.value){
- o2.xDesktop.notice("success", {x: "right", y:"top"}, MWF.xApplication.process.ProcessDesigner.LP.projectionRunSuccess, this.node);
- }else{
- o2.xDesktop.notice("error", {x: "right", y:"top"}, MWF.xApplication.process.ProcessDesigner.LP.projectionRunError, this.node);
- }
- });
- },
- changeProjectionItem: function(){
- if (this.currentItem) {
- this.modifyProjectionItem();
- }else{
- this.addProjectionItem();
- }
- },
- checkItemData: function(name, path, type){
- if (!name || !path){
- o2.xDesktop.notice("error", {x: "right", y:"top"}, MWF.xApplication.process.ProcessDesigner.LP.projectionInputError, this.node);
- return false;
- }
- var count = 0;
- for (var i=0; i<this.data.length; i++){
- if (this.data[i].type===type) count++;
- if (count>=this.options.maxTypeCount[type]){
- var txt = MWF.xApplication.process.ProcessDesigner.LP.projectionTypeCountError;
- txt = txt.replace(/{type}/g, type);
- txt = txt.replace(/{count}/g, this.options.maxTypeCount[type]);
- o2.xDesktop.notice("error", {x: "right", y:"top"}, txt, this.node);
- return false;
- }
- if (this.data[i].name===name && (!this.currentItem || this.data[i]!=this.currentItem.data)) {
- o2.xDesktop.notice("error", {x: "right", y:"top"}, MWF.xApplication.process.ProcessDesigner.LP.projectionSameNameError, this.node);
- return false;
- }
- }
- return true;
- },
- checkItemColumn: function(){
- var columnNames = {
- "string": 0,
- "long": 0,
- "double": 0,
- "boolean": 0,
- "date":0,
- "time": 0,
- "dateTime": 0
- };
- var rows = this.table.rows;
- for (var i=0; i<this.data.length; i++){
- columnNames[this.data[i].type]++;
- var n = columnNames[this.data[i].type] || 1;
- var c = this.data[i].type+"Value"+(n>=10 ? n : "0"+n);
- rows[i+1].cells[3].set("text", c);
- }
- },
- modifyProjectionItem: function(){
- var name = this.nameInput.get("value");
- var path = this.pathInput.get("value");
- var type = this.typeSelect.options[this.typeSelect.selectedIndex].value;
- if (this.checkItemData(name, path, type)){
- this.currentItem.data.name = name;
- this.currentItem.data.path = path;
- this.currentItem.data.type = type;
- this.currentItem.refresh();
- this.currentItem.unSelected();
- this.checkItemColumn();
- this.fireEvent("change");
- this.fireEvent("modifyItem");
- }
- },
- addProjectionItem: function(){
- var name = this.nameInput.get("value");
- var path = this.pathInput.get("value");
- var type = this.typeSelect.options[this.typeSelect.selectedIndex].value;
- if (this.checkItemData(name, path, type)){
- var o = { "name": name, "path": path, "type": type };
- this.data.push(o);
- new MWF.xApplication.process.ProcessDesigner.widget.ProjectionEditor.Item(o, this);
- this.checkItemColumn();
- this.fireEvent("change");
- this.fireEvent("addItem");
- }
- },
- loadProjectionList: function(){
- this.data.each(function(d){
- new MWF.xApplication.process.ProcessDesigner.widget.ProjectionEditor.Item(d, this);
- }.bind(this));
- this.checkItemColumn();
- }
- });
- MWF.xApplication.process.ProcessDesigner.widget.ProjectionEditor.Item = new Class({
- initialize: function(data, editor){
- this.editor = editor;
- this.data = data;
- this.table = this.editor.table;
- this.css = this.editor.css;
- this.load();
- },
- load: function(){
- this.tr = new Element('tr').inject(this.table);
- var td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.name);
- td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.path);
- td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.type);
- td = this.tr.insertCell().setStyles(this.css.projectionTableTd).set("text", this.data.type);
- td = this.tr.insertCell().setStyles(this.css.projectionTableTd);
- this.delAction = new Element("div", {"styles": this.css.projectionItemAction}).inject(td);
- this.setEvent();
- },
- setEvent: function(){
- this.delAction.addEvent("click", function(e){
- var txt = MWF.xApplication.process.ProcessDesigner.LP.projectionDeleteItem;
- txt = txt.replace(/{name}/g, this.data.name);
- txt = txt.replace(/{path}/g, this.data.path);
- var _self = this;
- MWF.xDesktop.confirm("infor", e, MWF.xApplication.process.ProcessDesigner.LP.projectionDeleteItemTitle, txt, 300, 120, function(){
- _self.destroy();
- this.close();
- }, function(){
- this.close();
- }, null, null, "o2");
- }.bind(this));
- this.tr.addEvents({
- "click": function(){
- var item = this.editor.currentItem;
- if (item) item.unSelected();
- if (item!==this) this.selected();
- }.bind(this)
- })
- },
- selected: function(){
- this.editor.currentItem = this;
- this.tr.setStyles(this.css.projectionTableTr_selected);
- this.editor.nameInput.set("value", this.data.name);
- this.editor.pathInput.set("value", this.data.path);
- var ops = this.editor.typeSelect.options;
- for (var i=0; i<ops.length; i++){
- if (ops[i].value===this.data.type){
- ops[i].set("selected", true);
- break;
- }
- }
- this.editor.actionNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.projectionActionNode_modify);
- },
- unSelected: function(){
- this.editor.currentItem = null;
- this.tr.setStyles(this.css.projectionTableTr);
- this.editor.actionNode.set("text", MWF.xApplication.process.ProcessDesigner.LP.projectionActionNode_add);
- },
- refresh: function(){
- var tds = this.tr.getElements("td");
- tds[0].set("text", this.data.name);
- tds[1].set("text", this.data.path);
- tds[2].set("text", this.data.type);
- },
- destroy: function(){
- this.unSelected();
- this.tr.destroy();
- this.editor.data.erase(this.data);
- this.editor.checkItemColumn();
- this.editor.fireEvent("change");
- this.editor.fireEvent("deleteItem");
- o2.release(this);
- }
- });
|