IconSelector.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. MWF.xApplication.process = MWF.xApplication.process || {};
  2. MWF.xApplication.process.ProcessDesigner = MWF.xApplication.process.ProcessDesigner || {};
  3. MWF.xApplication.process.ProcessDesigner.widget = MWF.xApplication.process.ProcessDesigner.widget || {};
  4. MWF.require("MWF.xAction.org.express.RestActions", null,false);
  5. MWF.require("MWF.widget.Identity", null, false);
  6. MWF.xApplication.process.ProcessDesigner.widget.PersonSelector = new Class({
  7. Implements: [Options, Events],
  8. Extends: MWF.widget.Common,
  9. options: {
  10. "style": "default",
  11. "type": "identity",
  12. "name": []
  13. },
  14. initialize: function(node, app, options){
  15. this.setOptions(options);
  16. this.node = $(node);
  17. this.app = app;
  18. this.path = "../x_component_process_ProcessDesigner/widget/$PersonSelector/";
  19. this.cssPath = "../x_component_process_ProcessDesigner/widget/$PersonSelector/"+this.options.style+"/css.wcss";
  20. this._loadCss();
  21. this.identitys = [];
  22. this.restActions = new MWF.xAction.org.express.RestActions();
  23. this.name = this.node.get("name");
  24. this.load();
  25. },
  26. load: function(data){
  27. this.node.setStyles(this.css.node);
  28. this.createAddNode();
  29. this.loadIdentitys();
  30. },
  31. loadIdentitys: function(){
  32. var explorer = {
  33. "actions": this.restActions,
  34. "app": {
  35. "lp": this.app.lp
  36. }
  37. }
  38. if (this.options.names){
  39. this.options.names.each(function(name){
  40. MWF.require("MWF.widget.Identity", function(){
  41. if (this.options.type.toLowerCase()=="identity") this.identitys.push(new MWF.widget.Identity({"name": name}, this.node, explorer));
  42. if (this.options.type.toLowerCase()=="department") this.identitys.push(new MWF.widget.Department({"name": name}, this.node, explorer));
  43. if (this.options.type.toLowerCase()=="company") this.identitys.push(new MWF.widget.Company({"name": name}, this.node, explorer));
  44. }.bind(this));
  45. }.bind(this));
  46. }
  47. },
  48. createAddNode: function(){
  49. this.addNode = new Element("div", {"styles": this.css.addPersonNode}).inject(this.node, "before");
  50. this.addNode.addEvent("click", function(e){
  51. var selecteds = [];
  52. this.identitys.each(function(id){selecteds.push(id.data.name)});
  53. var explorer = {
  54. "actions": this.restActions,
  55. "app": {
  56. "lp": this.app.lp
  57. }
  58. }
  59. var options = {
  60. "type": this.options.type,
  61. "count": (this.options.type.toLowerCase()=="duty")? 1: 0,
  62. "names": selecteds,
  63. "zIndex": 20000,
  64. "onComplete": function(items){
  65. this.identitys = [];
  66. if (this.options.type.toLowerCase()!="duty") this.node.empty();
  67. MWF.require("MWF.widget.Identity", function(){
  68. items.each(function(item){
  69. if (this.options.type.toLowerCase()=="identity") this.identitys.push(new MWF.widget.Identity(item.data, this.node, explorer));
  70. if (this.options.type.toLowerCase()=="department") this.identitys.push(new MWF.widget.Department(item.data, this.node, explorer));
  71. if (this.options.type.toLowerCase()=="company") this.identitys.push(new MWF.widget.Company(item.data, this.node, explorer));
  72. }.bind(this));
  73. if (this.options.type.toLowerCase()=="duty") {
  74. items.each(function(item){
  75. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector.DutyInput(this, item.data, this.node, explorer, 20000);
  76. }.bind(this));
  77. //var _self = this;
  78. //items.each(function(item){
  79. // item.data.id = new MWF.widget.UUID().toString();
  80. // this.identitys.push(new MWF.widget.Duty(item.data, this.node, explorer, true, function(){
  81. // _self.fireEvent("removeDuty", [this]);
  82. // }));
  83. //}.bind(this));
  84. }
  85. this.fireEvent("change", [this.identitys]);
  86. }.bind(this));
  87. }.bind(this)
  88. };
  89. var selector = new MWF.OrgSelector(this.app.content, options);
  90. }.bind(this));
  91. }
  92. });
  93. MWF.xApplication.process.ProcessDesigner.widget.PersonSelector.DutyInput = Class({
  94. Implements: [Events],
  95. initialize: function(selector, data, node, explorer, zIndex){
  96. this.itemNode = $(node);
  97. this.data = data;
  98. this.isNew = false;
  99. this.selector = selector;
  100. this.css = this.selector.css;
  101. this.app = this.selector.app;
  102. this.explorer = explorer;
  103. this.zIndex = zIndex;
  104. this.selector.identitys = [];
  105. this.load();
  106. },
  107. load: function(){
  108. this.css.dutyMaskNode["z-index"] = this.zIndex;
  109. this.app.content.mask({
  110. "destroyOnHide": true,
  111. "style": this.css.dutyMaskNode,
  112. });
  113. this.node = new Element("div", {
  114. "styles": this.css.dutyInputArea
  115. });
  116. this.titleNode = new Element("div", {
  117. "styles": this.css.dutyTitleNode
  118. }).inject(this.node);
  119. this.titleActionNode = new Element("div", {
  120. "styles": this.css.dutyTitleActionNode
  121. }).inject(this.titleNode);
  122. this.titleTextNode = new Element("div", {
  123. "styles": this.css.dutyTitleTextNode,
  124. "text": this.app.lp.dutyInputTitle
  125. }).inject(this.titleNode);
  126. this.contentNode = new Element("div", {
  127. "styles": this.css.dutyContentNode
  128. }).inject(this.node);
  129. this.loadContent();
  130. this.actionNode = new Element("div", {
  131. "styles": this.css.dutyActionNode
  132. }).inject(this.node);
  133. this.actionNode.setStyle("text-align", "center");
  134. this.loadAction();
  135. this.node.setStyle("z-index", this.zIndex.toInt()+1);
  136. this.node.inject(this.app.content);
  137. this.node.position({
  138. relativeTo: this.app.content,
  139. position: "center",
  140. edge: "center"
  141. });
  142. var size = this.app.content.getSize();
  143. var nodeSize = this.node.getSize();
  144. this.node.makeDraggable({
  145. "handle": this.titleNode,
  146. "limit": {
  147. "x": [0, size.x-nodeSize.x],
  148. "y": [0, size.y-nodeSize.y]
  149. }
  150. });
  151. this.setEvent();
  152. },
  153. setEvent: function(){
  154. if (this.titleActionNode){
  155. this.titleActionNode.addEvent("click", function(){this.selector.fireEvent("cancel"); this.close();}.bind(this));
  156. }
  157. this.okActionNode.addEvent("click", function(){
  158. this.selectDuty();
  159. this.close();
  160. }.bind(this));
  161. this.cancelActionNode.addEvent("click", function(){this.selector.fireEvent("cancel"); this.close();}.bind(this));
  162. },
  163. selectDuty: function(){
  164. var code = this.scriptEditor.editor.editor.getValue();
  165. this.data.code = code;
  166. if (!this.item){
  167. var dutyItem = new MWF.widget.Duty(this.data, this.itemNode, this.explorer, true, function(e){
  168. var _self = this;
  169. var text = this.selector.app.lp.deleteDutyText.replace(/{duty}/g, this.data.name);
  170. this.selector.app.confirm("warm", e, this.selector.app.lp.deleteDutyTitle, text, 300, 120, function(){
  171. _self.selector.fireEvent("removeDuty", [_self]);
  172. this.close();
  173. }, function(){
  174. this.close();
  175. });
  176. e.stopPropagation();
  177. });
  178. dutyItem.selector = this.selector;
  179. dutyItem.explorer = this.explorer;
  180. this.selector.identitys.push(dutyItem);
  181. this.selector.fireEvent("change", [this.selector.identitys]);
  182. }else{
  183. this.selector.identitys.push(this.item);
  184. this.selector.fireEvent("change", [this.selector.identitys]);
  185. }
  186. },
  187. "close": function(){
  188. this.node.destroy();
  189. this.app.content.unmask();
  190. MWF.release(this);
  191. delete this;
  192. },
  193. loadAction: function(){
  194. this.okActionNode = new Element("button", {
  195. "styles": this.css.dutyOkActionNode,
  196. "text": this.app.lp.selectorButton.ok
  197. }).inject(this.actionNode);
  198. this.cancelActionNode = new Element("button", {
  199. "styles": this.css.dutyCancelActionNode,
  200. "text": this.app.lp.selectorButton.cancel
  201. }).inject(this.actionNode);
  202. },
  203. loadContent: function(){
  204. this.contentAreaNode= new Element("div", {"styles": this.css.dutyContentAreaNode}).inject(this.contentNode);
  205. var text = this.app.lp.dutyInput.replace(/{duty}/g, this.data.name);
  206. this.textNode = new Element("div", {"styles": this.css.dutyTextNode, "text": text}).inject(this.contentAreaNode);
  207. this.referenceAreaNode = new Element("div", {"styles": this.css.dutyReferenceAreaNode}).inject(this.contentAreaNode);
  208. this.scriptAreaNode = new Element("div", {"styles": this.css.dutyScriptAreaNode}).inject(this.contentAreaNode);
  209. this.createScriptNode();
  210. this.createReference(this.app.lp.creatorCompany, "return this.workContext.getWork().creatorCompany");
  211. this.createReference(this.app.lp.creatorDepartment, "return this.workContext.getWork().creatorDepartment");
  212. this.createReference(this.app.lp.currentCompany, "return this.workContext.getTask().company");
  213. this.createReference(this.app.lp.currentDepartment, "return this.workContext.getTask().department");
  214. },
  215. createScriptNode: function(){
  216. this.scriptNode = new Element("div", {"styles": this.css.dutyScriptNode}).inject(this.scriptAreaNode);
  217. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.ScriptText", function(){
  218. this.scriptEditor = new MWF.xApplication.process.ProcessDesigner.widget.ScriptText(this.scriptNode, "", this.app, {
  219. "height": 316,
  220. "maskNode": this.app.content,
  221. "maxObj": this.app.content
  222. //"onChange": function(code){
  223. // _self.data[node.get("name")] = code;
  224. //}
  225. });
  226. this.scriptEditor.loadEditor();
  227. if (this.data.code) this.scriptEditor.editor.editor.setValue(this.data.code);
  228. }.bind(this));
  229. },
  230. createReference: function(text, code){
  231. var node = new Element("div", {"styles": this.css.dutyReferenceItemNode}).inject(this.referenceAreaNode);
  232. node.set("text", text);
  233. node.store("code", code);
  234. var css = this.css.dutyReferenceItemNode;
  235. var overcss = this.css.dutyReferenceItemNode_over;
  236. var downcss = this.css.dutyReferenceItemNode_down;
  237. var _self = this;
  238. node.addEvents({
  239. "mouseover": function(){this.setStyles(overcss);},
  240. "mouseout": function(){this.setStyles(css);},
  241. "mousedown": function(){this.setStyles(downcss);},
  242. "mouseup": function(){this.setStyles(overcss);},
  243. "click": function(){
  244. var code = this.retrieve("code");
  245. var value = _self.scriptEditor.editor.editor.getValue();
  246. if (!value){
  247. _self.scriptEditor.editor.editor.setValue(code);
  248. }else{
  249. value = value + "\n" +code;
  250. _self.scriptEditor.editor.editor.setValue(value);
  251. }
  252. }
  253. });
  254. }
  255. });
  256. MWF.widget.Duty = new Class({
  257. Extends: MWF.widget.Department,
  258. setEvent: function(){
  259. this.node.addEvent("click", function(){
  260. this.modifyDuty();
  261. }.bind(this));
  262. },
  263. modifyDuty: function(){
  264. var dutyInput = new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector.DutyInput(this.selector, this.data, this.selector.node, this.explorer, 20000);
  265. dutyInput.item = this;
  266. }
  267. });