PersonSelector.js 21 KB

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