PersonSelector.js 25 KB

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