IconSelector.js 12 KB

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