PersonSelector.js 19 KB

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