PersonSelector.js 20 KB

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