123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- MWF.xApplication.process.ProcessDesigner.widget = MWF.xApplication.process.ProcessDesigner.widget || {};
- MWF.xDesktop.requireApp("process.ProcessDesigner", "Property", null, false);
- MWF.xApplication.process.ProcessDesigner.widget.OrgEditor = new Class({
- Implements: [Options, Events],
- Extends: MWF.widget.Common,
- options: {
- "style": "default"
- },
- initialize: function(node, route, data, options){
- this.setOptions(options);
- this.node = $(node);
- if( !data ){
- this.data = [];
- }else{
- this.data = typeOf( data ) === "string" ? JSON.parse(data) : data;
- }
- this.route = route;
- this.process = route.process;
- this.path = "../x_component_process_ProcessDesigner/widget/$OrgEditor/";
- this.cssPath = "../x_component_process_ProcessDesigner/widget/$OrgEditor/"+this.options.style+"/css.wcss";
- this._loadCss();
- this.selectedItems = [];
- this.lp = MWF.xApplication.process.ProcessDesigner.LP;
- },
- load: function(){
- this.scrollNode = this.process.panel.propertyTabPage.contentNodeArea;
- this.toolbarNode = new Element("div", {"styles": this.css.toolbarNode}).inject(this.node);
- //this.previewNode = new Element("div", {
- // "styles": this.css.previewNode,
- // "title" : this.lp.preview
- //}).inject(this.toolbarNode);
- this.copyNode = new Element("div", {
- "styles": this.css.copyNode,
- "title" : this.lp.copy,
- "events" : {
- "click" : function( ev ){
- this.selectOtherConfig( ev )
- }.bind(this)
- }
- }).inject(this.toolbarNode);
- this.selectedNode = new Element("div", {"styles": this.css.selectedNode}).inject(this.node);
- this.upNode = new Element("div", { "styles": this.css.upNode, "text" : this.lp.orgEditor.addOption }).inject(this.node);
- this.upNode.addEvent("click", function( ev ){
- debugger;
- if( this.currentItem ){
- var d = this.currentItem.getData();
- if( !d.title || !d.name || d.name === "未命名" ){
- MWF.xDesktop.notice("error", {"y":"top", "x": "left"}, this.lp.notice.saveRouteOrgNoName, ev.target);
- return;
- }
- if( d.name.test(/^\d+$/) ){
- MWF.xDesktop.notice("error", {"y":"top", "x": "left"}, this.lp.notice.saveRouteOrgNumberId, ev.target);
- return;
- }
- if( d.name.indexOf("..") > -1 ){
- MWF.xDesktop.notice("error", {"y":"top", "x": "left"}, this.lp.notice.saveRouteOrgDoubleDotId, ev.target);
- return;
- }
- if( this.checkName(d.name, d.id ) ){
- this.currentItem.save();
- this.currentItem.unSelectItem();
- if( this.defaultProperty ){
- this.defaultProperty.show();
- }else{
- this.loadDefaultProperty();
- }
- this.scrollNode.scrollTo(0,0);
- this.upNode.set("text","添加选择项");
- }else{
- MWF.xDesktop.notice("error", {"y":"top", "x": "right"}, this.lp.orgEditor.conflictNotice+":"+ d.name, ev.target);
- }
- }else if( this.defaultProperty ){
- var d = this.defaultData;
- if( !d.title || !d.name || d.name === "未命名"){
- MWF.xDesktop.notice("error", {"y":"top", "x": "left"}, this.lp.notice.saveRouteOrgNoName, ev.target);
- return;
- }
- if( d.name.test(/^\d+$/) ){
- MWF.xDesktop.notice("error", {"y":"top", "x": "left"}, this.lp.notice.saveRouteOrgNumberId, ev.target);
- return;
- }
- if( d.name.indexOf("..") > -1 ){
- MWF.xDesktop.notice("error", {"y":"top", "x": "left"}, this.lp.notice.saveRouteOrgDoubleDotId, ev.target);
- return;
- }
- if( this.checkName(d.name, d.id ) ) {
- this.data.push(this.defaultData);
- this.createSelectedItem(this.defaultData);
- this.save();
- this.defaultProperty.propertyContent.destroy();
- this.loadDefaultProperty();
- this.upNode.set("text", this.lp.orgEditor.addOption);
- }else{
- MWF.xDesktop.notice("error", {"y":"top", "x": "right"}, this.lp.orgEditor.conflictNotice+":"+ d.name, ev.target);
- }
- }
- }.bind(this));
- this.propertyNode = new Element("div", {"styles": this.css.propertyNode}).inject(this.node);
- this.getTemplate( function(){
- this.loadSelectedItems();
- this.loadDefaultProperty();
- }.bind(this));
- this.setUpNodeFixed();
- },
- setUpNodeFixed : function(){
- var scrollNode = this.scrollNode;
- scrollNode.getParent().setStyle("position","relative");
- scrollNode.addEvent("scroll",function(ev){
- if( this.node.offsetParent === null )return;
- var position = this.propertyNode.getPosition( scrollNode );
- if( position.y < 30 ){
- this.upNode.setStyles({
- "position" : "absolute",
- "top" : 1,
- "left" : 0,
- "border" : "1px solid #ffa200",
- "background-color" : "#fff",
- "width" : "99%"
- })
- }else{
- this.upNode.setStyles({
- "position" : "static",
- "border" : "0px"
- })
- }
- }.bind(this))
- },
- loadSelectedItems: function(){
- this.data.each(function(itemData){
- this.selectedItems.push(new MWF.xApplication.process.ProcessDesigner.widget.OrgEditor.SelectedItem(this, itemData));
- }.bind(this));
- this.fireEvent("change");
- },
- createSelectedItem : function( itemData ){
- this.selectedItems.push(new MWF.xApplication.process.ProcessDesigner.widget.OrgEditor.SelectedItem(this, itemData));
- this.fireEvent("change");
- },
- getTemplate: function(callback){
- if (!this.templateJson){
- MWF.getJSON("../x_component_process_ProcessDesigner/widget/$OrgEditor/org.json", function(json){
- this.templateJson = json;
- if (callback) callback();
- }.bind(this));
- }else{
- if (callback) callback();
- }
- },
- save : function(){
- this.route.data.selectConfig = JSON.stringify(this.getData());
- },
- getData: function(){
- var data = [];
- this.selectedItems.each(function(item){
- data.push(item.getData());
- });
- this.data = data;
- return data;
- },
- checkName : function( name, id ){
- var flag = true;
- debugger;
- this.selectedItems.each(function(item){
- var d = item.getData();
- if( d.name === name && d.id !== id ){
- flag = false;
- }
- });
- return flag;
- },
- loadDefaultProperty: function(){
- this.defaultData = Object.clone(this.templateJson);
- this.defaultProperty = new MWF.APPPD.widget.OrgEditor.Property(this, this.defaultData, {
- "onPostLoad": function () {
- this.defaultProperty.show();
- }.bind(this)
- });
- this.defaultProperty.load();
- },
- selectOtherConfig : function( ev ){
- var selectableItems = [];
- if( this.process && this.process.routes ){
- Object.each( this.process.routes, function(route){
- if(route.data.selectConfig){
- var array = JSON.parse( route.data.selectConfig );
- if( array && array.length ){
- var json = {
- "name": route.data.name,
- "id": route.data.id,
- "subItemList" : []
- }
- array.each( function( d ){
- json.subItemList.push( { name : d.name + " - "+d.title, id : d.id , data : JSON.stringify(d) } );
- });
- selectableItems.push( json );
- }
- }
- });
- }
- o2.xDesktop.requireApp("Template", "Selector.Custom", function () {
- var options = {
- "count": 0,
- "title": this.lp.orgEditor.copyConfig,
- "selectableItems": selectableItems,
- "expand": true,
- "category": true,
- "onComplete": function (items) {
- if( items.length > 0 ){
- var idList = [];
- var nameConflictList = [];
- this.process.designer.actions.getId( items.length, function(ids){
- idList = ids.data;
- }.bind(this),null,false);
- items.each( function(item, i){
- var data = JSON.parse(item.data.data);
- data.id = idList[i].id;
- if( this.checkName( data.name, data.id ) ){
- this.selectedItems.push(new MWF.xApplication.process.ProcessDesigner.widget.OrgEditor.SelectedItem(this, data));
- }else{
- nameConflictList.push( data.name );
- }
- if( nameConflictList.length > 0 ){
- MWF.xDesktop.notice("error", {"y":"top", "x": "right"}, this.lp.orgEditor.conflictNotice+":"+ nameConflictList.join(","), ev.target);
- }
- }.bind(this));
- this.save();
- this.fireEvent("change");
- }
- }.bind(this)
- };
- var selector = new o2.xApplication.Template.Selector.Custom(this.process.designer.node, options);
- selector.load();
- }.bind(this))
- }
- });
- MWF.xApplication.process.ProcessDesigner.widget.OrgEditor.SelectedItem = new Class({
- initialize: function(editor, itemData){
- this.editor = editor;
- this.css = this.editor.css;
- this.data = itemData;
- if( !this.data.events || Object.keys(this.data.events).length === 0 ){
- this.data.events = Object.clone( this.editor.templateJson.events )
- }
- this.tmpData = Object.clone(itemData);
- this.node = new Element("div", {"styles": this.css.selectedItemNode}).inject(this.editor.selectedNode);
- this.load();
- },
- load: function(){
- this.textNode = new Element("div", {"styles": this.css.selectedItemTextNode}).inject(this.node);
- this.textNode.set({
- "text": this.data.name,
- "title": this.data.description
- });
- new Element("span", {
- "styles": this.css.selectedItemTextNode,
- "html" : ( this.data.title ? ("( "+this.data.title+" )") : "" )
- }).inject(this.textNode);
- this.selectTypeNode = new Element("div", {
- "styles": this.css.selectedItemLabelNode,
- "text" : this.editor.lp.selectType + ":"
- }).inject(this.node);
- new Element("span", {
- "styles": this.css.selectedItemTextNode,
- "text" : this.data.selectType === "identity" ? this.editor.lp.identity : this.editor.lp.unit
- }).inject(this.selectTypeNode);
- this.selectCountNode = new Element("div", {
- "styles": this.css.selectedItemLabelNode,
- "text" : this.editor.lp.selectCount + ":"
- }).inject(this.node);
- new Element("span", {
- "styles": this.css.selectedItemTextNode,
- "text" : this.data.selectType === "identity" ? this.data.identityCount : this.data.unitCount
- }).inject(this.selectCountNode);
- this.node.addEvents({
- "mouseover": function(){
- if (this.editor.currentItem!=this) this.node.setStyles(this.css.selectedItemNode_over);
- }.bind(this),
- "mouseout": function(){
- if (this.editor.currentItem!=this) this.node.setStyles(this.css.selectedItemNode);
- }.bind(this),
- "click": function(){this.selectItem();}.bind(this)
- });
- this.closeNode = new Element("div", {
- "styles": this.css.selectedItemCloseNode,
- "title" : this.editor.lp.delete
- }).inject(this.node);
- this.closeNode.addEvent("click", function(ev){
- this.deleteItem(ev);
- ev.stopPropagation();
- }.bind(this));
- //this.loadProperty();
- //this.selectItem();
- },
- reload : function(){
- this.node.empty();
- this.load();
- },
- save : function(){
- this.data = Object.clone( this.tmpData );
- this.editor.save();
- this.reload();
- },
- getData : function( isClone ){
- var d = this.tmpData || this.data;
- return isClone ? Object.clone(d) : d;
- },
- loadProperty: function(){
- this.property = new MWF.APPPD.widget.OrgEditor.Property(this.editor, this.tmpData, {
- "onPostLoad": function () {
- this.property.show();
- }.bind(this)
- });
- this.property.load();
- },
- deleteItem: function(e){
- var _self = this;
- MWF.xDesktop.confirm("warn", e, this.editor.lp.deleteOrgConfirmTitle, this.editor.lp.deleteOrgConfirmContent, "300", "100", function(){
- _self._deleteItem();
- this.close();
- }, function(){
- this.close();
- })
- },
- _deleteItem: function(){
- this.node.destroy();
- if (this.property) this.property.propertyContent.destroy();
- this.editor.selectedItems.erase(this);
- //this.editor.data.erase(this.data);
- this.editor.save();
- if (this.editor.currentItem === this) this.editor.currentItem = null;
- this.editor.fireEvent("change");
- if( !this.editor.currentItem ){
- if(this.editor.defaultProperty){
- this.editor.defaultProperty.show();
- this.editor.upNode.set("text",this.editor.lp.orgEditor.addOption);
- }
- }
- MWF.release(this);
- },
- selectItem: function(){
- this.editor.upNode.set("text", this.editor.lp.orgEditor.modifyOption);
- if(this.editor.currentItem) this.editor.currentItem.unSelectItem();
- if(this.editor.defaultProperty)this.editor.defaultProperty.hide();
- if (this.property){
- this.property.show();
- }else{
- this.loadProperty();
- }
- this.node.setStyles(this.css.selectedItemNode_check);
- this.editor.currentItem = this;
- },
- unSelectItem: function(){
- this.node.setStyles(this.css.selectedItemNode);
- if (this.property) this.property.hide();
- this.editor.currentItem = null;
- }
- });
- MWF.xApplication.process.ProcessDesigner.widget.OrgEditor.Property = new Class({
- Implements: [Options, Events],
- Extends: MWF.APPPD.Property,
- initialize: function(org, data, options){
- this.setOptions(options);
- this.org = org;
- this.process = org.route.process;
- this.paper = this.process.paper;
- this.node = org.propertyNode;
- this.data = data;
- if( !this.data.id ){
- this.process.designer.actions.getId(1, function(ids){
- this.data.id = ids.data[0].id;
- }.bind(this),null,false);
- }
- this.data.pid = this.data.id; //this.process.process.id+this.org.route.data.id+this.data.id;
- this.htmlPath = "../x_component_process_ProcessDesigner/widget/$OrgEditor/org.html";
- },
- show: function(){
- if (!this.process.options.isView){
- if (!this.propertyContent){
- this.getHtmlString(function(){
- this.htmlString = o2.bindJson(this.htmlString, {"lp": o2.APPPD.LP.propertyTemplate});
- this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.node);
- //this.process.panel.propertyTabPage.showTabIm();
- this.JsonTemplate = new MWF.widget.JsonTemplate(this.data, this.htmlString);
- this.propertyContent.set("html", this.JsonTemplate.load());
- //this.process.panel.data = this.data;
- this.setEditNodeEvent();
- this.setEditNodeStyles(this.propertyContent);
- this.loadPropertyTab();
- this.loadFormFieldInput();
- this.loadPersonInput();
- this.loadScriptInput();
- this.loadScriptText();
- this.loadScriptArea();
- this.loadUnitTypeSelector();
- this.loadEventsEditor();
- }.bind(this));
- //this.loadDutySelector();
- }else{
- //this.process.panel.data = this.data;
- this.propertyContent.setStyle("display", "block");
- //this.process.panel.propertyTabPage.showTabIm();
- }
- // this.process.isFocus = true;
- }
- },
- setEditNodeEvent: function(){
- var property = this;
- // var inputs = this.propertyContent.getElements(".editTableInput");
- var inputs = this.propertyContent.getElements("input");
- inputs.each(function(input){
- var jsondata = input.get("name");
- var id = this.data.id;
- input.set("name", id+jsondata);
- if (jsondata){
- var inputType = input.get("type").toLowerCase();
- switch (inputType){
- case "radio":
- input.addEvent("change", function(e){
- property.setRadioValue(jsondata, this);
- });
- input.addEvent("blur", function(e){
- property.setRadioValue(jsondata, this);
- });
- input.addEvent("keydown", function(e){
- e.stopPropagation();
- });
- property.setRadioValue(jsondata, input);
- break;
- case "checkbox":
- input.addEvent("keydown", function(e){
- e.stopPropagation();
- });
- break;
- default:
- input.addEvent("change", function(e){
- property.setValue(jsondata, this.value);
- });
- input.addEvent("blur", function(e){
- property.setValue(jsondata, this.value);
- });
- input.addEvent("keydown", function(e){
- if (e.code===13){
- property.setValue(jsondata, this.value);
- }
- e.stopPropagation();
- });
- property.setValue(jsondata, input.get("value"));
- }
- }
- }.bind(this));
- var selects = this.propertyContent.getElements("select");
- selects.each(function(select){
- var jsondata = select.get("name");
- if (jsondata){
- select.addEvent("change", function(e){
- property.setSelectValue(jsondata, this);
- });
- //property.setSelectValue(jsondata, select);
- }
- });
- var textareas = this.propertyContent.getElements("textarea");
- textareas.each(function(input){
- var jsondata = input.get("name");
- if (jsondata){
- input.addEvent("change", function(e){
- property.setValue(jsondata, this.value);
- });
- input.addEvent("blur", function(e){
- property.setValue(jsondata, this.value);
- });
- input.addEvent("keydown", function(e){
- e.stopPropagation();
- });
- }
- }.bind(this));
- },
- loadEventsEditor: function(){
- var events = this.propertyContent.getElement(".MWFEventsArea");
- if (events){
- var name = events.get("name");
- var eventsObj = this.data[name];
- if( !MWF.xApplication.process.FormDesigner )MWF.xApplication.process.FormDesigner = {};
- if( !MWF.xApplication.process.FormDesigner.widget )MWF.xApplication.process.FormDesigner.widget = {};
- MWF.xDesktop.requireApp("process.FormDesigner", "widget.EventsEditor", function(){
- var eventsEditor = new MWF.xApplication.process.FormDesigner.widget.EventsEditor(events, this.process.designer, {
- //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
- "maxObj": this.process.designer.content
- });
- eventsEditor.load(eventsObj, this.data, name);
- }.bind(this));
- }
- }
- });
|