PersonSelector.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. MWF.xApplication.process.ProcessDesigner = MWF.xApplication.process.ProcessDesigner || {};
  2. MWF.xApplication.process.ProcessDesigner.widget = MWF.xApplication.process.ProcessDesigner.widget || {};
  3. MWF.xDesktop.requireApp("Selector", "package", null, false);
  4. MWF.require("MWF.widget.O2Identity", 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. "count": 0,
  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_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 = MWF.Actions.get("x_organization_assemble_control");
  23. //this.restActions = new MWF.xApplication.Selector.Actions.RestActions();
  24. this.name = this.node.get("name");
  25. this.load();
  26. },
  27. load: function(){
  28. this.node.setStyles(this.css.node);
  29. this.createAddNode();
  30. this.loadIdentitys();
  31. },
  32. loadIdentitys: function(){
  33. if (this.options.names){
  34. if (this.options.type.toLowerCase()==="duty"){
  35. var dutys = JSON.decode(this.options.names);
  36. dutys.each(function(d){
  37. var dutyItem = new MWF.widget.O2Duty(d, this.node, {
  38. "canRemove": true,
  39. "onRemove": function(item, e){
  40. var _self = this;
  41. var text = this.app.lp.deleteDutyText.replace(/{duty}/g, item.data.name);
  42. this.app.confirm("warm", e, this.app.lp.deleteDutyTitle, text, 300, 120, function(){
  43. _self.identitys.erase(item);
  44. _self.fireEvent("removeDuty", [item]);
  45. this.close();
  46. }, function(){
  47. this.close();
  48. });
  49. e.stopPropagation();
  50. }.bind(this)
  51. });
  52. dutyItem.selector = this;
  53. this.identitys.push(dutyItem);
  54. }.bind(this));
  55. }else{
  56. this.options.names.each(function(name){
  57. if (name){
  58. var data = (typeOf(name)==="string") ? {"name": name, "id": name}: name;
  59. MWF.require("MWF.widget.O2Identity", function(){
  60. if (this.options.type.toLowerCase()==="identity") this.identitys.push(new MWF.widget.O2Identity(data, this.node));
  61. if (this.options.type.toLowerCase()==="unit") this.identitys.push(new MWF.widget.O2Unit(data, this.node));
  62. if (this.options.type.toLowerCase()==="person") this.identitys.push(new MWF.widget.O2Person(data, this.node));
  63. if (this.options.type.toLowerCase()==="application") this.identitys.push(new MWF.widget.O2Application(data, this.node));
  64. if (this.options.type.toLowerCase()==="process") this.identitys.push(new MWF.widget.O2Process(data, this.node));
  65. if (this.options.type.toLowerCase()==="formfield") this.identitys.push(new MWF.widget.O2FormField(data, this.node));
  66. if (this.options.type.toLowerCase()==="view") this.identitys.push(new MWF.widget.O2View(data, this.node));
  67. if (this.options.type.toLowerCase()==="cmsview") this.identitys.push(new MWF.widget.O2CMSView(data, this.node));
  68. if (this.options.type.toLowerCase()==="queryview") this.identitys.push(new MWF.widget.O2QueryView(data, this.node));
  69. if (this.options.type.toLowerCase()==="querystat") this.identitys.push(new MWF.widget.O2QueryStat(data, this.node));
  70. if (this.options.type.toLowerCase()==="dutyname") this.identitys.push(new MWF.widget.O2Duty(data, this.node));
  71. if (this.options.type.toLowerCase()==="cmsapplication") this.identitys.push(new MWF.widget.O2CMSApplication(data, this.node));
  72. if (this.options.type.toLowerCase()==="cmscategory") this.identitys.push(new MWF.widget.O2CMSCategory(data, this.node));
  73. }.bind(this));
  74. }
  75. }.bind(this));
  76. }
  77. }
  78. },
  79. createAddNode: function(){
  80. this.addNode = new Element("div", {"styles": this.css.addPersonNode}).inject(this.node, "before");
  81. this.addNode.addEvent("click", function(e){
  82. var selecteds = [];
  83. this.identitys.each(function(id){selecteds.push(id.data)});
  84. var options = {
  85. "type": (this.options.type.toLowerCase()==="dutyname") ? "duty" : this.options.type,
  86. "application": this.options.application,
  87. "fieldType": this.options.fieldType,
  88. "count": (this.options.type.toLowerCase()==="duty")? 1: this.options.count,
  89. "values": selecteds,
  90. "zIndex": 20000,
  91. "onComplete": function(items){
  92. this.identitys = [];
  93. if (this.options.type.toLowerCase()!=="duty") this.node.empty();
  94. MWF.require("MWF.widget.O2Identity", function(){
  95. items.each(function(item){
  96. if (this.options.type.toLowerCase()==="identity") this.identitys.push(new MWF.widget.O2Identity(item.data, this.node));
  97. if (this.options.type.toLowerCase()==="person") this.identitys.push(new MWF.widget.O2Person(item.data, this.node));
  98. if (this.options.type.toLowerCase()==="unit") this.identitys.push(new MWF.widget.O2Unit(item.data, this.node));
  99. if (this.options.type.toLowerCase()==="application") this.identitys.push(new MWF.widget.O2Application(item.data, this.node));
  100. if (this.options.type.toLowerCase()==="process") this.identitys.push(new MWF.widget.O2Process(item.data, this.node));
  101. if (this.options.type.toLowerCase()==="cmsapplication") this.identitys.push(new MWF.widget.O2CMSApplication(item.data, this.node));
  102. if (this.options.type.toLowerCase()==="cmscategory") this.identitys.push(new MWF.widget.O2CMSCategory(item.data, this.node));
  103. if (this.options.type.toLowerCase()==="formfield") this.identitys.push(new MWF.widget.O2FormField(item.data, this.node));
  104. if (this.options.type.toLowerCase()==="view") this.identitys.push(new MWF.widget.O2View(item.data, this.node));
  105. if (this.options.type.toLowerCase()==="cmsview") this.identitys.push(new MWF.widget.O2CMSView(item.data, this.node));
  106. if (this.options.type.toLowerCase()==="queryview") this.identitys.push(new MWF.widget.O2QueryView(item.data, this.node));
  107. if (this.options.type.toLowerCase()==="querystat") this.identitys.push(new MWF.widget.O2QueryStat(item.data, this.node));
  108. if (this.options.type.toLowerCase()==="dutyname") this.identitys.push(new MWF.widget.O2Duty(item.data, this.node));
  109. }.bind(this));
  110. if (this.options.type.toLowerCase()==="duty") {
  111. items.each(function(item){
  112. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector.DutyInput(this, item.data, this.node, 20000);
  113. }.bind(this));
  114. }
  115. this.fireEvent("change", [this.identitys]);
  116. }.bind(this));
  117. }.bind(this)
  118. };
  119. var selector = new MWF.O2Selector(this.app.content, options);
  120. }.bind(this));
  121. }
  122. });
  123. MWF.xApplication.process.ProcessDesigner.widget.PersonSelector.DutyInput = Class({
  124. Implements: [Events],
  125. initialize: function(selector, data, node, zIndex){
  126. this.itemNode = $(node);
  127. this.data = data;
  128. this.isNew = false;
  129. this.selector = selector;
  130. this.css = this.selector.css;
  131. this.app = this.selector.app;
  132. this.zIndex = zIndex;
  133. this.selector.identitys = [];
  134. this.referenceList = [];
  135. this.load();
  136. },
  137. load: function(){
  138. this.css.dutyMaskNode["z-index"] = this.zIndex;
  139. this.app.content.mask({
  140. "destroyOnHide": true,
  141. "style": this.css.dutyMaskNode,
  142. });
  143. this.node = new Element("div", {
  144. "styles": this.css.dutyInputArea
  145. });
  146. this.titleNode = new Element("div", {
  147. "styles": this.css.dutyTitleNode
  148. }).inject(this.node);
  149. this.titleActionNode = new Element("div", {
  150. "styles": this.css.dutyTitleActionNode
  151. }).inject(this.titleNode);
  152. this.titleTextNode = new Element("div", {
  153. "styles": this.css.dutyTitleTextNode,
  154. "text": this.app.lp.dutyInputTitle
  155. }).inject(this.titleNode);
  156. this.contentNode = new Element("div", {
  157. "styles": this.css.dutyContentNode
  158. }).inject(this.node);
  159. this.loadContent();
  160. this.actionNode = new Element("div", {
  161. "styles": this.css.dutyActionNode
  162. }).inject(this.node);
  163. this.actionNode.setStyle("text-align", "center");
  164. this.loadAction();
  165. this.node.setStyle("z-index", this.zIndex.toInt()+1);
  166. this.node.inject(this.app.content);
  167. this.node.position({
  168. relativeTo: this.app.content,
  169. position: "center",
  170. edge: "center"
  171. });
  172. var size = this.app.content.getSize();
  173. var nodeSize = this.node.getSize();
  174. this.node.makeDraggable({
  175. "handle": this.titleNode,
  176. "limit": {
  177. "x": [0, size.x-nodeSize.x],
  178. "y": [0, size.y-nodeSize.y]
  179. }
  180. });
  181. this.setEvent();
  182. },
  183. setEvent: function(){
  184. if (this.titleActionNode){
  185. this.titleActionNode.addEvent("click", function(){this.selector.fireEvent("cancel"); this.close();}.bind(this));
  186. }
  187. this.okActionNode.addEvent("click", function(){
  188. this.selectDuty();
  189. this.close();
  190. }.bind(this));
  191. this.cancelActionNode.addEvent("click", function(){this.selector.fireEvent("cancel"); this.close();}.bind(this));
  192. },
  193. selectDuty: function(){
  194. debugger;
  195. var code = this.scriptEditor.editor.editor.getValue();
  196. this.data.code = code;
  197. if (!this.item){
  198. var dutyItem = new MWF.widget.O2Duty(this.data, this.itemNode, {
  199. "canRemove": true,
  200. "onRemove": function(item, e){
  201. var _self = item;
  202. var text = item.selector.app.lp.deleteDutyText.replace(/{duty}/g, item.data.name);
  203. item.selector.app.confirm("warm", e, item.selector.app.lp.deleteDutyTitle, text, 300, 120, function(){
  204. _self.selector.identitys.erase(item);
  205. _self.selector.fireEvent("removeDuty", [item]);
  206. this.close();
  207. }, function(){
  208. this.close();
  209. });
  210. e.stopPropagation();
  211. }.bind(this)
  212. });
  213. dutyItem.selector = this.selector;
  214. this.selector.identitys.push(dutyItem);
  215. this.selector.fireEvent("change", [this.selector.identitys]);
  216. }else{
  217. this.selector.identitys.push(this.item);
  218. this.selector.fireEvent("change", [this.selector.identitys]);
  219. }
  220. },
  221. "close": function(){
  222. debugger;
  223. this.node.destroy();
  224. this.app.content.unmask();
  225. MWF.release(this);
  226. delete this;
  227. },
  228. loadAction: function(){
  229. this.okActionNode = new Element("button", {
  230. "styles": this.css.dutyOkActionNode,
  231. "text": "确 定"
  232. }).inject(this.actionNode);
  233. this.cancelActionNode = new Element("button", {
  234. "styles": this.css.dutyCancelActionNode,
  235. "text": "取 消"
  236. }).inject(this.actionNode);
  237. },
  238. loadContent: function(){
  239. this.contentAreaNode= new Element("div", {"styles": this.css.dutyContentAreaNode}).inject(this.contentNode);
  240. var text = this.app.lp.dutyInput.replace(/{duty}/g, this.data.name);
  241. this.textNode = new Element("div", {"styles": this.css.dutyTextNode, "text": text}).inject(this.contentAreaNode);
  242. this.referenceAreaNode = new Element("div", {"styles": this.css.dutyReferenceAreaNode}).inject(this.contentAreaNode);
  243. this.scriptAreaNode = new Element("div", {"styles": this.css.dutyScriptAreaNode}).inject(this.contentAreaNode);
  244. this.createScriptNode();
  245. // this.areaNode = new Element("div", {"styles": this.css.dutyAreaNode}).inject(this.contentAreaNode);
  246. // this.referenceAreaNode = new Element("div", {"styles": this.css.dutyReferenceAreaNode}).inject(this.areaNode);
  247. // this.contentAreaNode = new Element("div", {"styles": this.css.dutyContentAreaNode}).inject(this.areaNode);
  248. this.createReference(this.app.lp.creatorUnit, "return this.workContext.getWork().creatorUnitDn || this.workContext.getWork().creatorUnit;");
  249. this.createReference(this.app.lp.currentUnit, "return this.workContext.getTask().unitDn || this.workContext.getTask().unit;");
  250. this.createReference(this.app.lp.selectUnit, "", function(){
  251. var options = {
  252. "type": "unit",
  253. "count": 1,
  254. "onComplete": function(items){
  255. this.scriptEditor.editor.editor.setValue("return \""+items[0].data.distinguishedName+"\";");
  256. }.bind(this)
  257. };
  258. new MWF.O2Selector(this.node, options);
  259. }.bind(this));
  260. // this.createReference(this.app.lp.scriptUnit, "return this.workContext.getWork().creatorDepartment;");
  261. // this.createReference(this.app.lp.creatorCompany, "return this.workContext.getWork().creatorCompany");
  262. // this.createReference(this.app.lp.creatorDepartment, "return this.workContext.getWork().creatorDepartment");
  263. // this.createReference(this.app.lp.currentCompany, "return this.workContext.getTask().company");
  264. // this.createReference(this.app.lp.currentDepartment, "return this.workContext.getTask().department");
  265. },
  266. createScriptNode: function(){
  267. this.scriptNode = new Element("div", {"styles": this.css.dutyScriptNode}).inject(this.scriptAreaNode);
  268. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.ScriptText", function(){
  269. this.scriptEditor = new MWF.xApplication.process.ProcessDesigner.widget.ScriptText(this.scriptNode, "", this.app, {
  270. "height": 316,
  271. "maskNode": this.app.content,
  272. "maxObj": this.app.content
  273. //"onChange": function(code){
  274. // _self.data[node.get("name")] = code;
  275. //}
  276. });
  277. this.scriptEditor.loadEditor(function(){
  278. if (this.data.code) this.scriptEditor.editor.editor.setValue(this.data.code);
  279. }.bind(this));
  280. }.bind(this));
  281. },
  282. createReference: function(text, code, action){
  283. var node = new Element("div", {"styles": this.css.dutyReferenceItemNode}).inject(this.referenceAreaNode);
  284. node.set("text", text);
  285. node.store("code", code);
  286. node.store("action", action);
  287. var css = this.css.dutyReferenceItemNode;
  288. var overcss = this.css.dutyReferenceItemNode_over;
  289. var downcss = this.css.dutyReferenceItemNode_down;
  290. var _self = this;
  291. node.addEvents({
  292. "mouseover": function(){if (!this.retrieve("checked")) this.setStyles(overcss);},
  293. "mouseout": function(){if (!this.retrieve("checked")) this.setStyles(css);},
  294. "mousedown": function(){if (!this.retrieve("checked")) this.setStyles(downcss);},
  295. "mouseup": function(){if (!this.retrieve("checked")) this.setStyles(overcss);},
  296. "click": function(){
  297. // _self.checkedReference(this);
  298. var action = node.retrieve("action");
  299. if (action){
  300. action();
  301. }else{
  302. var code = this.retrieve("code");
  303. var value = _self.scriptEditor.editor.editor.getValue();
  304. if (!value){
  305. _self.scriptEditor.editor.editor.setValue(code);
  306. }else{
  307. value = value + "\n" +code;
  308. _self.scriptEditor.editor.editor.setValue(value);
  309. }
  310. }
  311. }
  312. });
  313. //this.referenceList.push(node);
  314. },
  315. // checkedReference: function(node){
  316. // this.referenceList.each(function(node){
  317. // this.unCheckedReference(node);
  318. // }.bind(this));
  319. // node.setStyles(this.css.dutyReferenceItemNode_down);
  320. // node.store("checked", true);
  321. // action = node.retrieve("action");
  322. // if (action) action();
  323. // },
  324. // unCheckedReference: function(node){
  325. // node.setStyles(this.css.dutyReferenceItemNode);
  326. // node.store("checked", false);
  327. // }
  328. });
  329. MWF.widget.O2Duty = new Class({
  330. Extends: MWF.widget.O2Group,
  331. getPersonData: function(){
  332. },
  333. setEvent: function(){
  334. this.node.addEvent("click", function(){
  335. this.modifyDuty();
  336. }.bind(this));
  337. },
  338. modifyDuty: function(){
  339. var dutyInput = new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector.DutyInput(this.selector, this.data, this.selector.node, 20000);
  340. dutyInput.item = this;
  341. }
  342. });