PersonSelector_bak.js 13 KB

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