PersonSelector.js 22 KB

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