PersonSelector.js 22 KB

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