PersonSelector.js 14 KB

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