UnitExplorer.js 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525
  1. MWF.require("MWF.widget.O2Identity", null, false);
  2. MWF.xDesktop.requireApp("Org", "$Explorer", null, false);
  3. MWF.xDesktop.requireApp("Template", "MTooltips", null, false);
  4. MWF.xApplication.Org.UnitExplorer = new Class({
  5. Extends: MWF.xApplication.Org.$Explorer,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "lp": {
  10. },
  11. "creator": false
  12. },
  13. _loadLp: function(){
  14. this.options.lp = {
  15. "search": this.app.lp.search,
  16. "searchText": this.app.lp.searchText,
  17. "elementSave": this.app.lp.organizationSave,
  18. "deleteElements": this.app.lp.deleteOrganization,
  19. "deleteElementsCancel": this.app.lp.deleteElementsCancel,
  20. "deleteElementsTitle": this.app.lp.deleteOrganizationTitle,
  21. "deleteElementsConfirm": this.app.lp.deleteOrganizationSubConfirm,
  22. "noSignature": this.app.lp.noSignature,
  23. "edit": this.app.lp.edit,
  24. "cancel": this.app.lp.cancel,
  25. "save": this.app.lp.save,
  26. "add": this.app.lp.add
  27. }
  28. },
  29. loadElements: function(addToNext){
  30. if (!this.isElementLoaded){
  31. if (!this.loaddingElement){
  32. this.loaddingElement = true;
  33. this._listElementNext(function(json){
  34. if (json.data.length){
  35. this.loadListContent(json.data);
  36. }else{
  37. if (!this.elements.length){
  38. this.setNoElementNoticeArea();
  39. }
  40. }
  41. this.loadElementQueue = 0;
  42. this.isElementLoaded = true;
  43. this.loaddingElement = false;
  44. }.bind(this));
  45. }else{
  46. if (addToNext) this.loadElementQueue++;
  47. }
  48. }
  49. },
  50. loadListContent: function(data){
  51. data.each(function(itemData, i){
  52. var item = this._newElement(itemData, this, i);
  53. this.elements.push(item);
  54. item.load();
  55. if (this.elements.length===1){
  56. item.selected();
  57. if (!item.isExpand) item.expand();
  58. }
  59. }.bind(this));
  60. },
  61. _listElementNext: function(callback){
  62. if (MWF.AC.isOrganizationManager() || MWF.AC.isSecurityManager()){
  63. this.actions.listTopUnit(function(json){
  64. if (callback) callback.apply(this, [json]);
  65. }.bind(this));
  66. }else{
  67. if (layout.session.user.identityList.length){
  68. var json = {"data": []};
  69. var unitNames = [];
  70. layout.session.user.identityList.each(function(id){
  71. var idFlag = (id.distinguishedName || id.id || id.unique || id.name);
  72. o2.Actions.get("x_organization_assemble_express").getUnitWithIdentityAndLevel({"identity": idFlag, "level": 1}, function(o){
  73. if (o.data){
  74. this.actions.getUnit(o.data.distinguishedName, function(u){
  75. if (unitNames.indexOf(u.data.distinguishedName)==-1){
  76. unitNames.push(u.data.distinguishedName);
  77. json.data.push(u.data);
  78. }
  79. }.bind(this),null, false);
  80. }
  81. }.bind(this), null, false);
  82. }.bind(this));
  83. if (callback) callback.apply(this, [json]);
  84. }
  85. }
  86. },
  87. _newElement: function(data, explorer){
  88. return new MWF.xApplication.Org.UnitExplorer.Unit(data, explorer, this.isEditor, 0);
  89. },
  90. _listElementByKey: function(callback, failure, key){
  91. this.actions.listUnitByKey(function(json){
  92. if (callback) callback.apply(this, [json]);
  93. }.bind(this), failure, key);
  94. },
  95. _getAddElementData: function(){
  96. return {
  97. "name": "",
  98. "unique": "",
  99. "typeList": ["company"],
  100. "description": "",
  101. "shortName": "",
  102. "superior": "",
  103. "orderNumber": "",
  104. "controllerList": [],
  105. "control": {
  106. "allowEdit": true,
  107. "allowDelete": true
  108. },
  109. "woSubDirectIdentityList": [],
  110. "woUnitAttributeList": [],
  111. "woUnitDutyList": []
  112. };
  113. },
  114. deleteSelectedElements: function(e){
  115. var _self = this;
  116. this.app.confirm("infor", e, this.options.lp.deleteElementsTitle, {"html": this.options.lp.deleteElementsConfirm}, 500, 260, function(){
  117. var deleted = [];
  118. var doCount = 0;
  119. var readyCount = _self.deleteElements.length;
  120. var errorText = "";
  121. var complete;
  122. complete = function () {
  123. if (doCount === readyCount) {
  124. if (errorText) {
  125. _self.app.notice(errorText, "error", _self.propertyContentNode, {x: "left", y: "top"});
  126. }
  127. }
  128. };
  129. _self.deleteElements.each(function(element){
  130. element["delete"](function(){
  131. deleted.push(element);
  132. doCount++;
  133. if (_self.deleteElements.length===doCount){
  134. _self.deleteElements = _self.deleteElements.filter(function (item) {
  135. return !deleted.contains(item);
  136. });
  137. _self.checkDeleteElements();
  138. }
  139. complete();
  140. }, function(error){
  141. errorText = (errorText) ? errorText+"<br/><br/>"+error : error;
  142. doCount++;
  143. if (_self.deleteElements.length !== doCount) {
  144. } else {
  145. _self.deleteElements = _self.deleteElements.filter(function (item) {
  146. return !deleted.contains(item);
  147. });
  148. _self.checkDeleteElements();
  149. }
  150. complete();
  151. });
  152. });
  153. this.close();
  154. }, function(){
  155. this.close();
  156. });
  157. }
  158. });
  159. MWF.xApplication.Org.UnitExplorer.Unit = new Class({
  160. Extends: MWF.xApplication.Org.$Explorer.Item,
  161. initialize: function(data, explorer, isEditor, i, listNode, parent){
  162. this.i = i;
  163. this.level = i;
  164. this.parent = parent;
  165. this.data = data;
  166. this.explorer = explorer;
  167. this.listNode = listNode || this.explorer.listNode;
  168. this.propertyContentNode = this.explorer.propertyContentNode;
  169. this.initStyle();
  170. this.selectedAttributes = [];
  171. this.isEdit = false;
  172. this.isEditor = isEditor;
  173. this.deleteSelected = false;
  174. this.subUnits = [];
  175. },
  176. refresh: function(){
  177. this._loadTextNode();
  178. if (this.content){
  179. if (this.content.titleInfor) this.content.titleInfor.refresh();
  180. if (this.content.bottomInfor) this.content.bottomInfor.refresh();
  181. }
  182. this.addActions();
  183. },
  184. initStyle: function(){
  185. var css = Object.clone(this.explorer.css.item);
  186. this.style = Object.merge(css, this.explorer.css.unitItem);
  187. },
  188. _loadTextNode: function(){
  189. this.textNode.set({"text": this.data.name+((this.data.subDirectUnitCount) ? " ("+(this.data.subDirectUnitCount)+")" : "")});
  190. },
  191. load: function(){
  192. this.node = new Element("div", {"styles": this.style.node}).inject(this.listNode);
  193. this.contentNode = new Element("div", {"styles": this.style.contentNode}).inject(this.node);
  194. var left = (10*this.level);
  195. this.contentNode.setStyle("padding-left", ""+left+"px");
  196. if ((this.level%2)===1){
  197. this.node.setStyle("background-color", "#ffffff");
  198. this.contentNode.setStyle("background-color", "#ffffff");
  199. }
  200. this.childNode = new Element("div", {"styles": this.style.childNode}).inject(this.node);
  201. this.toggleIconNode = new Element("div", {"styles": this.style.unitToggleIconNode}).inject(this.contentNode);
  202. this.setToggleIconNode();
  203. this.setToggleAction();
  204. this.iconNode = new Element("div", {"styles": this.style.unitIconNode}).inject(this.contentNode);
  205. var src = this._getIcon();
  206. this.iconNode.setStyle("background-image", "url("+src+")");
  207. this.actionNode = new Element("div", {"styles": this.style.actionNode}).inject(this.contentNode);
  208. this.textNode = new Element("div", {"styles": this.style.unitTextNode}).inject(this.contentNode);
  209. this._loadTextNode();
  210. this.setNewItem();
  211. this.node.inject(this.listNode);
  212. this.addActions();
  213. this.setEvent();
  214. },
  215. addActions: function(){
  216. //if (this.isEditor){
  217. if (this.data.id){
  218. if (this.data.control.allowDelete){
  219. if (!this.deleteNode){
  220. this.deleteNode = new Element("div.o2icon-delete", {"styles": this.style.actionDeleteNode}).inject(this.actionNode);
  221. this.deleteNode.addEvent("click", function(e){
  222. if (!this.notDelete){
  223. if (!this.deleteSelected){
  224. this.setDelete();
  225. }else{
  226. this.setUndelete();
  227. }
  228. }
  229. e.stopPropagation();
  230. }.bind(this));
  231. }
  232. }
  233. if (this.data.control.allowEdit){
  234. if (!this.addNode){
  235. this.addNode = new Element("div.o2icon-add", {"styles": this.style.actionAddNode}).inject(this.actionNode);
  236. this.addNode.addEvent("click", function(e){
  237. if (!this.notDelete){
  238. this.addSubUnit();
  239. }
  240. e.stopPropagation();
  241. }.bind(this));
  242. }
  243. }
  244. if (this.explorer.currentItem===this){
  245. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  246. if (this.addNode) this.addNode.setStyles(this.style.actionAddNode_selected);
  247. }
  248. }
  249. // }
  250. },
  251. addSubUnit: function(){
  252. this.expand(function(){
  253. var isNewElement = true;
  254. if (this.explorer.currentItem) isNewElement = this.explorer.currentItem.unSelected();
  255. if (isNewElement){
  256. var newElementData = this.explorer._getAddElementData();
  257. newElementData.superior = this.data.id;
  258. var item = new MWF.xApplication.Org.UnitExplorer.Unit(newElementData, this.explorer, this.isEditor, this.level+1, this.childNode, this);
  259. item.load();
  260. item.selected();
  261. item.editBaseInfor();
  262. (new Fx.Scroll(this.explorer.listScrollNode)).toElementCenter(item.node);
  263. }else{
  264. this.app.notice(this.explorer.options.lp.elementSave, "error", this.explorer.propertyContentNode);
  265. }
  266. }.bind(this));
  267. },
  268. setDeleteFromP: function(){
  269. this.notDelete = true;
  270. this.subUnits.each(function(unit){
  271. unit.setDeleteFromP();
  272. });
  273. this.deleteNode.setStyles(this.style.actionDeleteNode_delete);
  274. this.contentNode.setStyles(this.style.contentNode_delete);
  275. this.textNode.setStyles(this.style.unitTextNode);
  276. //this.explorer.deleteElements.push(this);
  277. this.deleteSelected = true;
  278. this.explorer.checkDeleteElements(this);
  279. },
  280. setDelete: function(){
  281. //this.actionNode.fade("in");
  282. this.subUnits.each(function(unit){
  283. unit.setDeleteFromP();
  284. });
  285. this.deleteNode.setStyles(this.style.actionDeleteNode_delete);
  286. if (this.addNode) this.addNode.setStyles(this.style.actionAddNode_delete);
  287. this.contentNode.setStyles(this.style.contentNode_delete);
  288. this.contentNode.removeClass("mainColor_bg");
  289. this.textNode.setStyles(this.style.unitTextNode);
  290. this.explorer.deleteElements.push(this);
  291. this.deleteSelected = true;
  292. this.deleteNode.removeClass("o2icon-delete").addClass("o2icon-off");
  293. this.explorer.checkDeleteElements(this);
  294. },
  295. setUndelete: function(){
  296. //this.actionNode.fade("out");
  297. this.notDelete = false;
  298. this.subUnits.each(function(unit){
  299. unit.setUndelete();
  300. });
  301. if (this.explorer.currentItem!==this){
  302. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode);
  303. if (this.addNode) this.addNode.setStyles(this.style.actionAddNode);
  304. this.contentNode.setStyles(this.style.contentNode);
  305. this.contentNode.removeClass("mainColor_bg");
  306. this.textNode.setStyles(this.style.unitTextNode);
  307. }else{
  308. this.contentNode.setStyles(this.style.contentNode_selected);
  309. this.contentNode.addClass("mainColor_bg");
  310. this.textNode.setStyles(this.style.textNode_selected);
  311. this.actionNode.setStyles(this.style.actionNode_selected);
  312. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  313. if (this.addNode) this.addNode.setStyles(this.style.actionAddNode_selected);
  314. if (this.addNode) this.addNode.setStyles(this.style.actionAddNode_selected);
  315. }
  316. this.deleteNode.removeClass("o2icon-off").addClass("o2icon-delete");
  317. this.explorer.deleteElements.erase(this);
  318. this.deleteSelected = false;
  319. this.explorer.checkDeleteElements(this);
  320. },
  321. setToggleIconNode: function(){
  322. if (this.data.subDirectUnitCount>0){
  323. var toggle_on = (this.explorer.currentItem===this) ? "toggle_current_on" : "toggle_on";
  324. var toggle_off = (this.explorer.currentItem===this) ? "toggle_current_off" : "toggle_off";
  325. if (this.isExpand){
  326. this.toggleIconNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/"+toggle_on+".png)");
  327. }else{
  328. this.toggleIconNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/"+toggle_off+".png)");
  329. }
  330. }else{
  331. this.toggleIconNode.setStyle("background-image", "");
  332. }
  333. },
  334. setToggleAction: function(){
  335. this.toggleIconNode.addEvent("click", function(e){
  336. this.expandOrCollapse();
  337. e.stopPropagation();
  338. }.bind(this));
  339. },
  340. expandOrCollapse: function(){
  341. if (this.isExpand){
  342. this.collapse();
  343. }else{
  344. this.expand();
  345. }
  346. },
  347. listSubUnit: function(callback){
  348. this.node.mask();
  349. this.explorer.actions.listSubUnitDirect(function(json){
  350. if (json.data.length){
  351. json.data.each(function(itemData){
  352. var item = new MWF.xApplication.Org.UnitExplorer.Unit(itemData, this.explorer, this.isEditor, this.level+1, this.childNode, this);
  353. this.explorer.elements.push(item);
  354. item.load();
  355. this.subUnits.push(item);
  356. }.bind(this));
  357. }
  358. this.isLoadSub = true;
  359. this.node.unmask();
  360. if (callback) callback();
  361. }.bind(this), null, this.data.id);
  362. },
  363. expand: function(callback){
  364. this.childNode.setStyle("display", "block");
  365. this.isExpand = true;
  366. this.setToggleIconNode();
  367. if (!this.isLoadSub){
  368. this.listSubUnit(callback);
  369. }else{
  370. if (callback) callback();
  371. }
  372. },
  373. collapse: function(){
  374. this.childNode.setStyle("display", "none");
  375. this.isExpand = false;
  376. this.setToggleIconNode();
  377. },
  378. unSelected: function(){
  379. if (this.content.baseInfor.mode==="edit") return false;
  380. this.explorer.currentItem = null;
  381. this.contentNode.setStyles(this.style.contentNode);
  382. this.textNode.setStyles(this.style.unitTextNode);
  383. this.actionNode.setStyles(this.style.actionNode);
  384. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode);
  385. if (this.addNode) this.addNode.setStyles(this.style.actionAddNode);
  386. if (this.deleteNode)this.deleteNode.removeClass("mainColor_color");
  387. if (this.addNode)this.addNode.removeClass("mainColor_color");
  388. this.iconNode.setStyle("background-image", "url("+this._getIcon()+")");
  389. this.contentNode.removeClass("mainColor_bg");
  390. this.contentNode.removeClass("mainColor_bg_opacity");
  391. this.setToggleIconNode();
  392. this.clearItemProperty();
  393. return true;
  394. },
  395. selected: function(){
  396. this.explorer.currentItem = this;
  397. this.contentNode.setStyles(this.style.contentNode_selected);
  398. this.textNode.setStyles(this.style.textNode_selected);
  399. this.actionNode.setStyles(this.style.actionNode_selected);
  400. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  401. if (this.addNode) this.addNode.setStyles(this.style.actionAddNode_selected);
  402. if (this.deleteNode)this.deleteNode.removeClass("mainColor_color");
  403. if (this.addNode)this.addNode.removeClass("mainColor_color");
  404. this.iconNode.setStyle("background-image", "url("+this._getIcon()+")");
  405. this.contentNode.addClass("mainColor_bg");
  406. this.contentNode.removeClass("mainColor_bg_opacity");
  407. this.setToggleIconNode();
  408. this.showItemProperty();
  409. },
  410. showItemProperty: function(){
  411. this.content = new MWF.xApplication.Org.UnitExplorer.UnitContent(this);
  412. },
  413. "delete": function(success, failure){
  414. this.explorer.actions.deleteUnit(this.data.id, function(){
  415. this.destroy();
  416. if (success) success();
  417. }.bind(this), function(xhr, text, error){
  418. var errorText = error;
  419. if (xhr) errorText = xhr.responseText;
  420. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  421. if (failure) failure();
  422. });
  423. },
  424. _getIcon: function(){
  425. return (this.explorer.currentItem===this) ? "../x_component_Org/$Explorer/default/icon/unit_current.png" : "../x_component_Org/$Explorer/default/icon/unit.png";
  426. },
  427. _isActionManager: function(){
  428. return (MWF.AC.isOrganizationManager() || MWF.AC.isUnitManager());
  429. }
  430. });
  431. MWF.xApplication.Org.UnitExplorer.UnitContent = new Class({
  432. Extends: MWF.xApplication.Org.$Explorer.ItemContent,
  433. _getData: function(callback){
  434. if (this.item.data.id){
  435. this.explorer.actions.getUnit(function(json){
  436. this.data = json.data;
  437. this.item.data = json.data;
  438. if (callback) callback();
  439. }.bind(this), null, this.item.data.id);
  440. }else{
  441. this.data = this.item.data;
  442. if (callback) callback();
  443. }
  444. },
  445. _showItemPropertyTitle: function(){
  446. this.titleInfor = new MWF.xApplication.Org.UnitExplorer.UnitContent.TitleInfor(this);
  447. },
  448. _showItemPropertyBottom: function(){
  449. this.bottomInfor = new MWF.xApplication.Org.UnitExplorer.UnitContent.BottomInfor(this);
  450. },
  451. loadItemPropertyTab: function(callback){
  452. this.propertyTabContainerNode = new Element("div", {"styles": this.item.style.tabTitleNode}).inject(this.propertyContentNode, "top");
  453. MWF.require("MWF.widget.Tab", function(){
  454. this.propertyTab = new MWF.widget.Tab(this.propertyContentNode, {"style": "unit", "useMainColor":true});
  455. this.propertyTab.load();
  456. this.propertyTab.tabNodeContainer.inject(this.propertyTabContainerNode);
  457. if (callback) callback();
  458. }.bind(this));
  459. },
  460. _loadTabs: function(){
  461. this.baseContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  462. this.basePage = this.propertyTab.addTab(this.baseContentNode, this.explorer.app.lp.unitBaseText);
  463. this.personMemberContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  464. this.personMemberPage = this.propertyTab.addTab(this.personMemberContentNode, this.explorer.app.lp.unitPersonMembers);
  465. this.dutyContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  466. this.dutyPage = this.propertyTab.addTab(this.dutyContentNode, this.explorer.app.lp.unitDutys);
  467. if (this.data.control.allowEdit){
  468. this.attributeContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  469. this.attributePage = this.propertyTab.addTab(this.attributeContentNode, this.explorer.app.lp.unitAttribute);
  470. }
  471. },
  472. _loadContent: function(){
  473. this._listBaseInfor();
  474. this.loadListCount();
  475. this._listIdentityMembers();
  476. this._listDutys();
  477. if (this.data.control.allowEdit) this._listAttributes();
  478. //var _self = this;
  479. // this.personMemberList = this._listMembers("personList", "woSubDirectIdentityList", this.personMemberContentNode, [{
  480. // "get": function(){
  481. // var src = _self.explorer.actions.getPersonIcon(this.person);
  482. // return "<div style='width:24px; height:24px;''><img style='width:24px; height:24px; border-radius:12px; border: 0' src='"+src+"'/></div>";
  483. // },
  484. // "set": function(){}
  485. // }, "name", "employee", "mobile", "mail"], [
  486. // {"style": "width: 30px", "text": ""},
  487. // {"style": "width: 20%", "text": this.explorer.app.lp.personName},
  488. // {"style": "", "text": this.explorer.app.lp.personEmployee},
  489. // {"style": "", "text": this.explorer.app.lp.personMobile},
  490. // {"style": "", "text": this.explorer.app.lp.personMail}
  491. // ], this.addPersonMember.bind(this), "personCountNode");
  492. //
  493. // this.groupMemberList = this._listMembers("groupList", "woGroupList", this.groupMemberContentNode, ["name", "distinguishedName", "description"], [
  494. // {"style": "width: 20%", "text": this.explorer.app.lp.groupName},
  495. // {"style": "width: 40%", "text": this.explorer.app.lp.groupDn},
  496. // {"style": "", "text": this.explorer.app.lp.groupDescription}
  497. // ], this.addGroupMember.bind(this), "groupCountNode");
  498. },
  499. loadListCount: function(){
  500. var identityCount = this.data.woSubDirectIdentityList.length;
  501. if (identityCount){
  502. if (this.identityCountNode){
  503. this.identityCountNode.set("text", identityCount);
  504. }else{
  505. this.identityCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": identityCount}).inject(this.personMemberPage.tabNode);
  506. }
  507. }else{
  508. if (this.identityCountNode) this.identityCountNode.destroy();
  509. }
  510. var dutyCount = this.data.woUnitDutyList.length;
  511. if (dutyCount){
  512. if (this.dutyCountNode){
  513. this.dutyCountNode.set("text", dutyCount);
  514. }else{
  515. this.dutyCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": dutyCount}).inject(this.dutyPage.tabNode);
  516. }
  517. }else{
  518. if (this.dutyCountNode) this.dutyCountNode.destroy();
  519. }
  520. if (this.data.control.allowEdit){
  521. var attributeCount = this.data.woUnitAttributeList.length;
  522. if (attributeCount){
  523. if (this.attributeCountNode){
  524. this.attributeCountNode.set("text", attributeCount);
  525. }else{
  526. this.attributeCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": attributeCount}).inject(this.attributePage.tabNode);
  527. }
  528. }else{
  529. if (this.attributeCountNode) this.attributeCountNode.destroy();
  530. }
  531. }
  532. },
  533. _listBaseInfor: function(){
  534. this.baseInfor = new MWF.xApplication.Org.UnitExplorer.UnitContent.BaseInfor(this);
  535. },
  536. getDutyActionPermission: function(){
  537. if( MWF.AC.isManager() )return true;
  538. if( MWF.AC.isSecurityManager() )return true;
  539. if( MWF.AC.isSystemManager() )return false;
  540. return this.data.control.allowEdit;
  541. },
  542. _listDutys: function(){
  543. var _self = this;
  544. this.dutyList = new MWF.xApplication.Org.List(this.dutyContentNode, this, {
  545. "action": _self.getDutyActionPermission(),
  546. "saveAction": "saveUnitduty",
  547. "deleteAction": "deleteUnitduty",
  548. "data": {
  549. "description":"",
  550. "name": "",
  551. "unique": "",
  552. "unit": this.data.id,
  553. "orderNumber": "",
  554. "identityList": [],
  555. "woIdentityList": []
  556. },
  557. "attr": ["name", "description", {
  558. "get": function(){
  559. //var html = "";
  560. // this.woIdentityList.each(function(identity){
  561. // html+="<div>"+identity.name+"</div>"
  562. // }.bind(this));
  563. return "";
  564. },
  565. "events": {
  566. "init": function(){
  567. //var divs = this.td.getElements("div");
  568. var contentNode = this.td;
  569. if (this.item.list.options.action){
  570. var actionDiv = new Element("div", {"styles": _self.item.style.dutyIdentityAction}).inject(this.td);
  571. contentNode = new Element("div", {"styles": _self.item.style.dutyIdentityContent}).inject(this.td);
  572. actionDiv.addEvent("click", function(){
  573. _self.editDutyIdentity(this.data, contentNode);
  574. }.bind(this));
  575. }
  576. var _dutyData = this.data;
  577. this.data.woIdentityList.each(function(identity, i){
  578. new MWF.widget.O2Identity(identity, contentNode, {
  579. "lazy" : true,
  580. "canRemove": _self.data.control.allowEdit,
  581. "onRemove": function(O2Identity, e){
  582. _self.deleteDutyIdentity(_dutyData, e, O2Identity);
  583. }
  584. })
  585. }.bind(this));
  586. },
  587. "click": function(){
  588. //_self.explorer.openGroup(this.data, this.td);
  589. }
  590. }
  591. }],
  592. "onPostSave": function(item, id){
  593. if (!item.data.id){
  594. item.data.id = id;
  595. this.data.woUnitDutyList.push(item.data);
  596. }
  597. this.loadListCount();
  598. }.bind(this),
  599. "onPostDelete": function(delCount){
  600. if (this.dutyCountNode){
  601. var count = this.dutyCountNode.get("text").toInt()-delCount;
  602. this.dutyCountNode.set("text", count);
  603. }
  604. }.bind(this),
  605. });
  606. //this.dutyList.addItem = function(){this.addDuty();};
  607. this.dutyList.load([
  608. {"style": "width: 20%", "text": this.explorer.app.lp.dutyName},
  609. {"style": "", "text": this.explorer.app.lp.description},
  610. {"style": "width: 50%", "text": this.explorer.app.lp.dutyMembers}
  611. ]);
  612. this.data.woUnitDutyList.each(function(item){
  613. //this.attributes.push(new MWF.xApplication.Org.PersonExplorer.PersonAttribute(this.attributeTabContentNode.getElement("table").getFirst(), item, this, this.explorer.css.list));
  614. this.dutyList.push(item);
  615. }.bind(this));
  616. },
  617. editDutyIdentity: function(dutyData, contentNode){
  618. var _self = this;
  619. MWF.xDesktop.requireApp("Selector", "Identity", function(){
  620. var selector = new MWF.xApplication.Selector.Identity(this.explorer.app.content,{
  621. "values": dutyData.identityList,
  622. "onComplete": function(items){
  623. var woIdentityList = [];
  624. var identityList = [];
  625. var dData = Object.clone(dutyData);
  626. items.each(function(item, i){
  627. woIdentityList.push(item.data);
  628. identityList.push(item.data.id);
  629. }.bind(this));
  630. dData.identityList = identityList;
  631. dData.woIdentityList = woIdentityList;
  632. _self.saveDuty(dData, function () {
  633. contentNode.empty();
  634. items.each(function(item, i){
  635. new MWF.widget.O2Identity(item.data, contentNode, {
  636. "canRemove": true,
  637. "onRemove": function(O2Identity, e){
  638. _self.deleteDutyIdentity(dutyData, e, O2Identity);
  639. }
  640. })
  641. }.bind(this));
  642. dutyData.identityList = identityList;
  643. dutyData.woIdentityList = woIdentityList;
  644. }.bind(this));
  645. }.bind(this)
  646. });
  647. selector.load();
  648. }.bind(this));
  649. },
  650. deleteDutyIdentity: function(dutyData, e, O2Identity){
  651. var _self = this;
  652. var text = this.explorer.app.lp.deleteDutyIdentity.replace(/{duty}/g, dutyData.name);
  653. text = text.replace(/{identity}/g, O2Identity.data.name);
  654. this.explorer.app.confirm("warn", e, this.explorer.app.lp.deleteDutyIdentityTitle, text, "360", "170", function(){
  655. dutyData.identityList.erase(O2Identity.data.id);
  656. dutyData.woIdentityList = dutyData.woIdentityList.filter(function(a){
  657. return (O2Identity.data.id !== a.id);
  658. });
  659. _self.saveDuty(dutyData, function(){
  660. O2Identity.destroy();
  661. });
  662. this.close();
  663. }, function(){
  664. this.close();
  665. });
  666. },
  667. saveDuty: function(data, callback){
  668. this.propertyContentScrollNode.mask({
  669. "style": {
  670. "opacity": 0.7,
  671. "background-color": "#999"
  672. }
  673. });
  674. this.explorer.actions.saveUnitduty(data, function(){
  675. this.propertyContentScrollNode.unmask();
  676. if (callback) callback();
  677. }.bind(this), function(xhr, text, error){
  678. var errorText = error;
  679. if (xhr) errorText = xhr.responseText;
  680. this.explorer.app.notice("request json error: "+errorText, "error");
  681. this.propertyContentScrollNode.unmask();
  682. }.bind(this));
  683. },
  684. _listAttributes: function(){
  685. this.attributeList = new MWF.xApplication.Org.List(this.attributeContentNode, this, {
  686. "action": this.data.control.allowEdit,
  687. "saveAction": "saveUnitattribute",
  688. "deleteAction": "deleteUnitattribute",
  689. "data": {
  690. "description":"",
  691. "name": "",
  692. "unique": "",
  693. "unit": this.data.id,
  694. "orderNumber": "",
  695. "attributeList": []
  696. },
  697. "attr": ["name", {
  698. "get": function(){return this.attributeList.join(",")},
  699. "set": function(value){this.attributeList = value.split(/,\s*/g)}
  700. }, "description"],
  701. "onPostSave": function(item, id){
  702. if (!item.data.id){
  703. item.data.id = id;
  704. this.data.woUnitAttributeList.push(item.data);
  705. }
  706. this.loadListCount();
  707. }.bind(this),
  708. "onPostDelete": function(delCount){
  709. if (this.attributeCountNode){
  710. var count = this.attributeCountNode.get("text").toInt()-delCount;
  711. this.attributeCountNode.set("text", count);
  712. }
  713. }.bind(this),
  714. });
  715. this.attributeList.load([
  716. {"style": "width: 20%", "text": this.explorer.app.lp.attributeName},
  717. {"style": "width: 45%", "text": this.explorer.app.lp.attributeValue},
  718. {"style": "", "text": this.explorer.app.lp.description}
  719. ]);
  720. this.data.woUnitAttributeList.each(function(item){
  721. //this.attributes.push(new MWF.xApplication.Org.PersonExplorer.PersonAttribute(this.attributeTabContentNode.getElement("table").getFirst(), item, this, this.explorer.css.list));
  722. this.attributeList.push(item);
  723. }.bind(this));
  724. },
  725. getIdentityActionPermission: function(){
  726. if( MWF.AC.isManager() )return true;
  727. if( MWF.AC.isSecurityManager() )return true;
  728. if( MWF.AC.isSystemManager() )return false;
  729. return this.data.control.allowEdit;
  730. },
  731. getIdentitySortActionPermission: function(){
  732. if( MWF.AC.isManager() )return true;
  733. if( MWF.AC.isSecurityManager() )return false;
  734. if( MWF.AC.isSystemManager() )return false;
  735. return this.data.control.allowEdit;
  736. },
  737. _listIdentityMembers: function(){
  738. var _self = this;
  739. if(this.identityMemberList){
  740. this.identityMemberList.clear();
  741. }
  742. this.personMemberContentNode.empty();
  743. this.identityMemberList = new MWF.xApplication.Org.List(this.personMemberContentNode, this, {
  744. "action": _self.getIdentityActionPermission(),
  745. "canEdit": false,
  746. "deleteAction": "deleteIdentity",
  747. "deleteItemTitle": this.explorer.app.lp.deleteIdentityMemeberTitle,
  748. "deleteItemText": this.explorer.app.lp.deleteIdentityMemeber,
  749. "data": {},
  750. "attr": [{
  751. "getHtml": function(){
  752. var src = _self.explorer.actions.getPersonIcon(this.woPerson.id);
  753. return "<div style='width:24px; height:24px;''><img style='width:24px; height:24px; border-radius:12px; border: 0' src='"+src+"'/></div>";
  754. },
  755. "set": function(){}
  756. }, {
  757. "get": function(){return this.woPerson.name}
  758. }, {
  759. "get": function(){return this.woPerson.employee}
  760. }, {
  761. "get": function(){return this.woPerson.mobile}
  762. }, {
  763. "get": function(){return this.woPerson.mail}
  764. }, {
  765. "getHtml": function(){
  766. return "<div style='float:right;width:24px; height:24px; background:url(../x_component_Org/$Explorer/"+
  767. _self.explorer.app.options.style+"/icon/open.png) center center no-repeat'></div>";
  768. },
  769. "events": {
  770. "click": function(){
  771. _self.explorer.openPerson(this.data.woPerson, this.td);
  772. }
  773. }
  774. }, {
  775. "getHtml": function(){
  776. if(_self.getIdentityActionPermission()){
  777. return "<div style='-webkit-user-select: none; -moz-user-select: none; width:24px; height:24px; cursor: move; background:url(../x_component_Org/$Explorer/"+
  778. _self.explorer.app.options.style+"/icon/move.png) center center no-repeat'></div>";
  779. }else{
  780. return "<div></div>"
  781. }
  782. },
  783. "events": {
  784. "selectstart": function(e){e.stopPropagation(); e.preventDefault();return false;},
  785. "touchstart": function(e){if(_self.getIdentityActionPermission())_self.startOrder(this.item, this.td, e)},
  786. "mousedown": function(e){if(_self.getIdentityActionPermission())_self.startOrder(this.item, this.td, e)}
  787. }
  788. }],
  789. "onPostDelete": function(delCount){
  790. if (this.identityCountNode){
  791. var count = this.identityCountNode.get("text").toInt()-delCount;
  792. this.identityCountNode.set("text", count);
  793. }
  794. }.bind(this),
  795. "onPostLoadAction": function () {
  796. debugger;
  797. if( _self.getIdentitySortActionPermission() ){
  798. this.sortAction = new Element("div", {"styles": this.css.sortActionNode, "text": _self.explorer.app.lp.sortByPinYin}).inject(this.actionNode);
  799. this.sortAction.addEvent("click", function (e) {
  800. _self.sortByPinYin(e)
  801. })
  802. this.sortByManualAction = new Element("div", {"styles": this.css.sortActionNode, "text": _self.explorer.app.lp.sortByManual}).inject(this.actionNode);
  803. this.sortByManualAction.addEvent("click", function (e) {
  804. _self.sortByManual(e)
  805. })
  806. }
  807. }
  808. });
  809. this.identityMemberList.addItem = this.addPersonMember.bind(this);
  810. this.identityMemberList.load([
  811. {"style": "width: 30px", "text": ""},
  812. {"style": "width: 20%", "text": this.explorer.app.lp.personName},
  813. {"style": "", "text": this.explorer.app.lp.personEmployee},
  814. {"style": "", "text": this.explorer.app.lp.personMobile},
  815. {"style": "", "text": this.explorer.app.lp.personMail},
  816. {"style": "width: 100px", "text": ""},
  817. {"style": "width: 100px", "text": ""}
  818. ]);
  819. this.data.woSubDirectIdentityList.each(function(id){
  820. var item = this.identityMemberList.push(id);
  821. }.bind(this));
  822. },
  823. sortByManual: function(){
  824. var _self = this;
  825. if(this.identityMemberList)this.identityMemberList.clear();
  826. this.identityMemberList = null;
  827. this.personMemberContentNode.empty();
  828. this.identitySortList = new MWF.xApplication.Org.List(this.personMemberContentNode, this, {
  829. "action": false,
  830. "canEdit": false,
  831. "attr": [{
  832. "getHtml": function(){
  833. var src = _self.explorer.actions.getPersonIcon(this.woPerson.id);
  834. return "<div style='width:24px; height:24px;''><img style='width:24px; height:24px; border-radius:12px; border: 0' src='"+src+"'/></div>";
  835. },
  836. "set": function(){}
  837. }, {
  838. "get": function(){return this.woPerson.name}
  839. }, {
  840. "get": function(){return this.woPerson.employee}
  841. }, {
  842. "get": function(){return this.woPerson.mobile}
  843. }, {
  844. "get": function(){return this.woPerson.mail}
  845. }, {
  846. "getHtml": function(){
  847. return "<input class='orderNumber' type='number' min=1 value='"+this.orderNumber+"'/>";
  848. }
  849. }]
  850. });
  851. this.identitySortList.loadAction = function(){
  852. this.actionAreaNode = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.contentNode, "top");
  853. this.actionNode = new Element("div", {"styles": this.css.actionNode}).inject(this.actionAreaNode);
  854. this.sortCancelAction = new Element("div", {"styles": this.css.cancelActionNode, "text": _self.explorer.app.lp.cancel}).inject(this.actionNode);
  855. this.sortCancelAction.addEvent("click", function (e) {
  856. _self._listIdentityMembers(e)
  857. })
  858. this.sortOkAction = new Element("div", {"styles": this.css.okActionNode, "text": _self.explorer.app.lp.ok}).inject(this.actionNode);
  859. this.sortOkAction.addEvent("click", function (e) {
  860. var pList = [];
  861. _self.identitySortList.items.each(function(item){
  862. item.data.orderNumber = item.tr.tr.getElement(".orderNumber").get("value").toInt();
  863. var p = o2.Actions.load("x_organization_assemble_control").IdentityAction.edit(item.data.id, item.data);
  864. pList.push(p);
  865. })
  866. Promise.all(pList).then(function () {
  867. _self.data.woSubDirectIdentityList.sort(function(a, b){
  868. return a.orderNumber - b.orderNumber;
  869. })
  870. _self._listIdentityMembers(e)
  871. })
  872. })
  873. };
  874. this.identitySortList.load([
  875. {"style": "width: 30px", "text": ""},
  876. {"style": "width: 20%", "text": this.explorer.app.lp.personName},
  877. {"style": "", "text": this.explorer.app.lp.personEmployee},
  878. {"style": "", "text": this.explorer.app.lp.personMobile},
  879. {"style": "", "text": this.explorer.app.lp.personMail},
  880. {"style": "", "text": this.explorer.app.lp.orderNumber}
  881. ]);
  882. this.data.woSubDirectIdentityList.each(function(id){
  883. var item = this.identitySortList.push(id);
  884. }.bind(this));
  885. },
  886. sortByPinYin : function(e){
  887. var _self = this;
  888. this.explorer.app.confirm("infor", e, this.explorer.app.lp.sortByPinYin, {"html": this.explorer.app.lp.sortByPinYinConfirmContent}, 300, 180, function(){
  889. debugger;
  890. var list = _self.data.woSubDirectIdentityList;
  891. list.sort( function(a, b){
  892. return a.name.localeCompare(b.name);
  893. });
  894. for( var i=0; i<list.length; i++ ){
  895. _self.explorer.actions.orderIdentity(list[i].id, "(0)", function(){}, null, false);
  896. }
  897. _self.identityMemberList.clear();
  898. list.each(function(id){
  899. var item = _self.identityMemberList.push(id);
  900. }.bind(this));
  901. this.close();
  902. }, function(){
  903. this.close();
  904. });
  905. },
  906. startOrder: function(item, td, e){
  907. var tr = td.getParent("tr");
  908. var table = tr.getParent("table");
  909. var div = td.getFirst("div");
  910. var size = tr.getSize();
  911. var titleTr = table.getElement("tr");
  912. var _self = this;
  913. var moveNode = new Element("table", {"styles": {
  914. "opacity": 0.3,
  915. "border": "0px dashed #999",
  916. "z-index": 10000,
  917. "width": size.x,
  918. "height": size.y,
  919. "background-color": "#CCC",
  920. "position": "absolute"
  921. }}).inject(this.explorer.app.content);
  922. var moveNodeTr = tr.clone().inject(moveNode);
  923. var moveTds = moveNodeTr.getElements("td");
  924. titleTr.getElements("th").each(function(cell, i){
  925. moveTds[i].setStyle("width", ""+cell.getSize().x+"px");
  926. });
  927. moveNode.position({
  928. relativeTo: tr,
  929. position: 'upperLeft',
  930. edge: 'upperLeft'
  931. });
  932. div.setStyle("display", "none");
  933. var nextData = {};
  934. var ntr = tr.getNext("tr");
  935. if (ntr) nextData = ntr.retrieve("data");
  936. if (!nextData) nextData={};
  937. var drag = new Drag.Move(moveNode, {
  938. // "container": table,
  939. "droppables": table.getElements("tr").erase(tr),
  940. "preventDefault": true,
  941. "stopPropagation": true,
  942. "onStart": function(){
  943. tr.setStyles({
  944. // "display": "none",
  945. "background-color": "#dff3fc"
  946. });
  947. }.bind(this),
  948. "onEnter": function(element, droppable){
  949. tr.inject(droppable, "after");
  950. droppable.setStyles({"background": "#fcf8f1"});
  951. tr.setStyles({"display": "table-row"});
  952. // element.setStyles({"display": "none"});
  953. var nextTr = tr.getNext("tr");
  954. if (nextTr){
  955. nextData = nextTr.retrieve("data");
  956. }else{
  957. nextData={};
  958. }
  959. if (!nextData) nextData={};
  960. },
  961. "onLeave": function(element, droppable){
  962. droppable.setStyles({"background": "transparent"});
  963. // tr.setStyles({"display": "none"});
  964. element.setStyles({"display": "block"});
  965. },
  966. "onDrop": function(dragging, droppable, e){
  967. if (droppable){
  968. var nextTr = tr.getNext("tr");
  969. if (nextTr){
  970. nextData = nextTr.retrieve("data");
  971. }else{
  972. nextData={};
  973. }
  974. if (!nextData) nextData={};
  975. moveNode.destroy();
  976. droppable.setStyles({"background": "transparent"});
  977. // tr.setStyles({"background": "transparent "});
  978. this.fadeTr(tr);
  979. this.explorer.actions.orderIdentity(item.data.id, nextData.id || "(0)", function(){});
  980. div.setStyle("display", "block");
  981. }else{
  982. _self.cancelDrag(dragging, div, tr, drag);
  983. }
  984. }.bind(this),
  985. "onCancel": function(dragging){
  986. _self.cancelDrag(dragging, div, tr, drag);
  987. }
  988. });
  989. drag.start(e);
  990. },
  991. cancelDrag: function(dragging, div, tr, drag){
  992. if (dragging) dragging.destroy();
  993. drag = null;
  994. div.setStyle("display", "block");
  995. this.fadeTr(tr);
  996. // tr.setStyles({
  997. // "display": "table-row",
  998. // "background-color": "transparent"
  999. // });
  1000. },
  1001. fadeTr: function(tr){
  1002. tr.setStyles({"display": "table-row"});
  1003. tr.morph({
  1004. "background-color": "#fdfdfd"
  1005. });
  1006. window.setTimeout(function(){
  1007. tr.setStyles({"background-color": "transparent"});
  1008. }, 800);
  1009. },
  1010. addPersonMember: function(){
  1011. this.checkSaveBaseInfor(function(){
  1012. MWF.xDesktop.requireApp("Selector", "Person", function(){
  1013. var selector = new MWF.xApplication.Selector.Person(this.explorer.app.content,{
  1014. "values": [],
  1015. "onComplete": function(items){
  1016. var data = {
  1017. "description": "",
  1018. "name": "",
  1019. "unique": "",
  1020. "person": "",
  1021. "department": "",
  1022. "unit": this.data.id,
  1023. "orderNumber": ""
  1024. };
  1025. items.each(function(item){
  1026. var idData = Object.clone(data);
  1027. idData.name = item.data.name;
  1028. idData.person = item.data.id;
  1029. this.explorer.actions.saveIdentity(idData, function(d){
  1030. this.explorer.actions.getIdentity(function(id){
  1031. this.data.woSubDirectIdentityList.push(id.data);
  1032. this.identityMemberList.push(id.data);
  1033. this.loadListCount();
  1034. }.bind(this), null, d.data.id);
  1035. }.bind(this));
  1036. }.bind(this));
  1037. }.bind(this)
  1038. });
  1039. selector.load();
  1040. }.bind(this));
  1041. }.bind(this));
  1042. },
  1043. checkSaveBaseInfor: function(callback){
  1044. if (!this.data.id){
  1045. if (this.baseInfor){
  1046. if (this.baseInfor.mode==="edit") this.baseInfor.save(function(){
  1047. if (callback) callback();
  1048. }.bind(this));
  1049. }
  1050. }else{
  1051. if (callback) callback();
  1052. }
  1053. }
  1054. });
  1055. MWF.xApplication.Org.UnitExplorer.UnitContent.TitleInfor = new Class({
  1056. Extends: MWF.xApplication.Org.$Explorer.ItemContent.TitleInfor,
  1057. _getStyle: function(){
  1058. var css = Object.clone(this.item.style.person);
  1059. return Object.merge(css, this.item.style.role);
  1060. },
  1061. _getIcon: function(){
  1062. return "../x_component_Org/$Explorer/default/icon/unit70.png";
  1063. },
  1064. setBackground: function(){
  1065. this.titleBgNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/unit_bg_bg.png)");
  1066. this.titleNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/unit_bg.png)");
  1067. },
  1068. loadRightInfor: function(){
  1069. //var text = this.data.name+((this.data.unique) ? "("+this.data.unique+")" : "");
  1070. var text = this.data.name;
  1071. if (!this.nameNode) this.nameNode = new Element("div", {"styles": this.style.titleInforNameNode}).inject(this.titleInforRightNode);
  1072. if (!this.signatureNode) this.signatureNode = new Element("div", {"styles": this.style.titleInforSignatureNode}).inject(this.titleInforRightNode);
  1073. this.nameNode.set("text", text);
  1074. this.signatureNode.set("text", (this.data.levelName || "" ));
  1075. }
  1076. });
  1077. MWF.xApplication.Org.UnitExplorer.UnitContent.BottomInfor = new Class({
  1078. Extends: MWF.xApplication.Org.$Explorer.ItemContent.BottomInfor,
  1079. addInforList: function(){
  1080. var text = this.explorer.app.lp.unitReadDn.replace(/{dn}/g, (this.data.distinguishedName || " "));
  1081. this.addInfor(text);
  1082. text = this.explorer.app.lp.unitReadLevel.replace(/{level}/g, (this.data.level || " "));
  1083. text = text.replace(/{levelName}/g, (this.data.levelName || " "));
  1084. this.addInfor(text);
  1085. text = this.explorer.app.lp.unitReadCreate.replace(/{date}/g, (this.data.createTime || " "));
  1086. text = text.replace(/{date2}/g, (this.data.updateTime || " "));
  1087. this.addInfor(text);
  1088. }
  1089. });
  1090. MWF.xApplication.Org.UnitExplorer.UnitContent.BaseInfor = new Class({
  1091. initialize: function(content){
  1092. this.content = content;
  1093. this.item = content.item;
  1094. this.data = this.item.data;
  1095. this.explorer = this.item.explorer;
  1096. this.contentNode = this.content.baseContentNode;
  1097. this.style = this.item.style.person;
  1098. this.attributes = [];
  1099. this.mode = "read";
  1100. this.load();
  1101. },
  1102. load: function(){
  1103. this.node = new Element("div", {"styles": this.style.baseContentNode}).inject(this.contentNode);
  1104. this.editContentNode = new Element("div", {"styles": this.style.baseEditNode}).inject(this.node);
  1105. this.editContentNode.set("html", this.getContentHtml());
  1106. var n = this.editContentNode.getElement(".infor_name");
  1107. if (n) n.set("text", this.data.name || "");
  1108. var n = this.editContentNode.getElement(".infor_unique");
  1109. if (n) n.set("text", this.data.unique || "");
  1110. var n = this.editContentNode.getElement(".infor_type");
  1111. if (n) n.set("text", this.data.typeList.join(", ") || "");
  1112. var n = this.editContentNode.getElement(".infor_shortName");
  1113. if (n) n.set("text", this.data.shortName || "");
  1114. var n = this.editContentNode.getElement(".infor_description");
  1115. if (n) n.set("text", this.data.description || "");
  1116. var n = this.editContentNode.getElement(".infor_orderNumber");
  1117. if (n) n.set("text", this.data.orderNumber || "");
  1118. this.editContentNode.getElements("td.inforTitle").setStyles(this.style.baseInforTitleNode);
  1119. this.editContentNode.getElements("td.inforContent").setStyles(this.style.baseInforContentNode);
  1120. this.editContentNode.getElements("td.inforAction").setStyles(this.style.baseInforActionNode);
  1121. var tdContents = this.editContentNode.getElements("td.inforContent");
  1122. if (this.data.control.allowEdit || o2.AC.isSecurityManager() ){
  1123. if (this.data.controllerList){
  1124. this.data.controllerList.each(function(id){
  1125. new MWF.widget.O2Person({"name": id}, tdContents[5], {"style": "xform"});
  1126. }.bind(this));
  1127. }
  1128. if (this.data.superior) new MWF.widget.O2Unit({"name": this.data.superior}, tdContents[6], {"style": "xform"});
  1129. }
  1130. this.loadAction();
  1131. },
  1132. getContentHtml: function(){
  1133. var html = "<table width='100%' cellpadding='3px' cellspacing='5px'>";
  1134. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.unitName+":</td><td class='inforContent infor_name'></td>";
  1135. if (this.data.control.allowEdit || o2.AC.isSecurityManager()) html += "<td class='inforTitle'>"+this.explorer.app.lp.unitUnique+":</td><td class='inforContent infor_unique'></td>";
  1136. html += "</tr><tr><td class='inforTitle'>"+this.explorer.app.lp.unitTypeList+":</td><td class='inforContent infor_type'></td>" +
  1137. "<td class='inforTitle'>"+this.explorer.app.lp.unitShortName+":</td><td class='inforContent infor_shortName'></td></tr>";
  1138. // html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.unitLevel+":</td><td class='inforContent'>"+this.data.level+"</td>" +
  1139. // "<td class='inforTitle'>"+this.explorer.app.lp.unitLevelName+":</td><td class='inforContent'>"+(this.data.levelName || "")+"</td></tr>";
  1140. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.unitDescription+":</td><td colspan='3' class='inforContent infor_description'></td>";
  1141. if (this.data.control.allowEdit || o2.AC.isSecurityManager()){
  1142. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.unitControllerList+":</td><td class='inforContent'></td>" +
  1143. "<td class='inforTitle'>"+this.explorer.app.lp.unitSuperUnit+":</td><td class='inforContent'></td></tr>";
  1144. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.orderNumber+":</td><td colspan='3' class='inforContent infor_orderNumber'></td></tr>";
  1145. }
  1146. html += "<tr><td colspan='4' class='inforAction'></td></tr>";
  1147. //this.baseInforRightNode.set("html", html);
  1148. return html;
  1149. },
  1150. loadAction: function(){
  1151. //this.explorer.app.lp.edit
  1152. var actionAreas = this.editContentNode.getElements("td");
  1153. var actionArea = actionAreas[actionAreas.length-1];
  1154. if (this.data.control.allowEdit){
  1155. this.baseInforEditActionAreaNode = new Element("div", {"styles": this.style.baseInforEditActionAreaNode}).inject(actionArea);
  1156. this.editNode = new Element("div", {"styles": this.style.actionEditNode, "text": this.explorer.app.lp.editUnit}).inject(this.baseInforEditActionAreaNode);
  1157. this.saveNode = new Element("div", {"styles": this.style.actionSaveNode, "text": this.explorer.app.lp.saveUnit}).inject(this.baseInforEditActionAreaNode);
  1158. this.saveNode.addClass("mainColor_bg");
  1159. this.cancelNode = new Element("div", {"styles": this.style.actionCancelNode, "text": this.explorer.app.lp.cancel}).inject(this.baseInforEditActionAreaNode);
  1160. this.editNode.setStyle("display", "block");
  1161. this.editNode.addEvent("click", this.edit.bind(this));
  1162. this.saveNode.addEvent("click", this.save.bind(this));
  1163. this.cancelNode.addEvent("click", this.cancel.bind(this));
  1164. }else{
  1165. }
  1166. },
  1167. edit: function(){
  1168. var tdContents = this.editContentNode.getElements("td.inforContent");
  1169. tdContents[0].setStyles(this.style.baseInforContentNode_edit).empty();
  1170. this.nameInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[0]);
  1171. this.nameInputNode.set("value", (this.data.name));
  1172. tdContents[1].setStyles(this.style.baseInforContentNode_edit).empty();
  1173. this.uniqueInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[1]);
  1174. this.uniqueInputNode.set("value", (this.data.unique));
  1175. if( this.data.id ){
  1176. this.tooltip = new MWF.xApplication.Org.UnitExplorer.UnitContent.UniqueTooltip(this.explorer.app.content, tdContents[1], this.explorer.app, {}, {
  1177. axis : "y",
  1178. position : {
  1179. x : "right"
  1180. },
  1181. hiddenDelay : 300,
  1182. displayDelay : 300
  1183. });
  1184. }
  1185. tdContents[2].setStyles(this.style.baseInforContentNode_edit).empty();
  1186. this.typeListInputNode = new Element("input", {"styles": this.style.inputNode_type}).inject(tdContents[2]);
  1187. this.typeListInputNode.set("value", ((this.data.typeList.length) ? this.data.typeList.join(", "): ""));
  1188. this.loadUnitTypeSelect();
  1189. tdContents[3].setStyles(this.style.baseInforContentNode_edit).empty();
  1190. this.shortNameInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[3]);
  1191. this.shortNameInputNode.set("value", (this.data.shortName || ""));
  1192. tdContents[4].setStyles(this.style.baseInforContentNode_edit).empty();
  1193. this.descriptionInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[4]);
  1194. this.descriptionInputNode.set("value", (this.data.description || ""));
  1195. tdContents[5].setStyles(this.style.baseInforContentNode_edit).empty();
  1196. this.controllerListInputNode = new Element("div", {"styles": this.style.inputNode_person}).inject(tdContents[5]);
  1197. tdContents[6].setStyles(this.style.baseInforContentNode_edit).empty();
  1198. this.superUnitInputNode = new Element("div", {"styles": this.style.inputNode_person}).inject(tdContents[6]);
  1199. tdContents[7].setStyles(this.style.baseInforContentNode_edit).empty();
  1200. this.orderNumberInputNode = new Element("input", {"styles": this.style.inputNode, "type":"number"}).inject(tdContents[7]);
  1201. this.orderNumberInputNode.set("value", (this.data.orderNumber || ""));
  1202. //this.controllerListInputNode.set("value", ((this.data.controllerList) ? this.data.controllerList.join(", ") : ""));
  1203. if (this.data.superior) new MWF.widget.O2Unit({"name": this.data.superior}, this.superUnitInputNode, {"style": "xform"});
  1204. this.superUnitInputNode.addEvent("click", function(){
  1205. MWF.xDesktop.requireApp("Selector", "package", function(){
  1206. var options = {
  1207. "type": "unit",
  1208. "values": [this.data.superior] || [],
  1209. "count": 1,
  1210. "onComplete": function(items){
  1211. this.superUnitInputNode.empty();
  1212. this.data.oldSuperior = this.data.superior;
  1213. if (items.length){
  1214. this.data.superior = items[0].data.id;
  1215. new MWF.widget.O2Unit({"name": this.data.superior}, this.superUnitInputNode, {"style": "xform"})
  1216. }else{
  1217. this.data.superior = "";
  1218. }
  1219. }.bind(this)
  1220. };
  1221. var selector = new MWF.O2Selector(this.explorer.app.content, options);
  1222. }.bind(this));
  1223. }.bind(this));
  1224. if (this.data.controllerList){
  1225. this.data.controllerList.each(function(id){
  1226. new MWF.widget.O2Person({"name": id}, this.controllerListInputNode, {"style": "xform"});
  1227. }.bind(this));
  1228. }
  1229. this.controllerListInputNode.addEvent("click", function(){
  1230. MWF.xDesktop.requireApp("Selector", "package", function(){
  1231. var options = {
  1232. "type": "person",
  1233. "values": this.data.controllerList || [],
  1234. "count": 0,
  1235. "onComplete": function(items){
  1236. this.data.oldControllerList = this.data.controllerList;
  1237. var controllerList = [];
  1238. this.controllerListInputNode.empty();
  1239. items.each(function(item){
  1240. controllerList.push(item.data.id);
  1241. new MWF.widget.O2Person(item.data, this.controllerListInputNode, {"style": "xform"});
  1242. }.bind(this));
  1243. this.data.controllerList = controllerList;
  1244. }.bind(this)
  1245. };
  1246. var selector = new MWF.O2Selector(this.explorer.app.content, options);
  1247. }.bind(this));
  1248. }.bind(this));
  1249. var _self = this;
  1250. this.editContentNode.getElements("input").addEvents({
  1251. "focus": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_focus);}},
  1252. "blur": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_blur);}}
  1253. });
  1254. this.mode = "edit";
  1255. this.editNode.setStyle("display", "none");
  1256. this.saveNode.setStyle("display", "block");
  1257. this.cancelNode.setStyle("display", "block");
  1258. },
  1259. loadUnitTypeSelect: function(){
  1260. if (this.typeListInputNode){
  1261. this.typeListInputNode.addEvents({
  1262. "blur": function(){this.hideTypeSelectNode();}.bind(this),
  1263. "click": function(){this.showTypeSelectNode();}.bind(this),
  1264. "focus": function(){this.showTypeSelectNode();}.bind(this)
  1265. });
  1266. }
  1267. },
  1268. hideTypeSelectNode: function(){
  1269. if (this.typeSelectNode) this.typeSelectNode.destroy();
  1270. this.typeSelectNode = null;
  1271. },
  1272. showTypeSelectNode: function(){
  1273. if (!this.typeSelectNode){
  1274. this.typeSelectNode = new Element("div", {"styles": this.style.typeSelectNode}).inject(this.typeListInputNode, "after");
  1275. var size = this.typeListInputNode.getSize();
  1276. var width = size.x-3;
  1277. this.typeSelectNode.setStyle("width", ""+width+"px");
  1278. this.typeSelectNode.position({
  1279. "relativeTo": this.typeListInputNode,
  1280. "position": 'bottomLeft',
  1281. "edge": 'upperLeft',
  1282. "offset": {"x": 1, "y": -3}
  1283. });
  1284. this.explorer.actions.listUnitType(function(json){
  1285. var count = json.data.valueList.length;
  1286. var height = (count*30);
  1287. this.typeSelectNode.setStyle("height", ""+height+"px");
  1288. json.data.valueList.each(function(t, i){
  1289. this.createTypeSelectItem(t, i);
  1290. }.bind(this));
  1291. }.bind(this));
  1292. }
  1293. },
  1294. createTypeSelectItem: function(text, i){
  1295. var typeSelectItemNode = new Element("div", {"styles": this.style.typeSelectItemNode}).inject(this.typeSelectNode);
  1296. if ((i % 2)===0) typeSelectItemNode.setStyle("background", "#f4f9ff");
  1297. var iconNode = new Element("div", {"styles": this.style.typeSelectItemIconNode}).inject(typeSelectItemNode);
  1298. var textNode = new Element("div", {"styles": this.style.typeSelectItemTextNode}).inject(typeSelectItemNode);
  1299. textNode.set("text", text);
  1300. var _self = this;
  1301. typeSelectItemNode.addEvents({
  1302. "mouseover": function(){this.setStyle("background-color", "#fef5e7");},
  1303. "mouseout": function(){this.setStyle("background", "#ffffff"); if ((i % 2)===0) this.setStyle("background", "#f4f9ff");},
  1304. "mousedown": function(){
  1305. _self.typeListInputNode.set("value", this.get("text"));
  1306. }
  1307. });
  1308. },
  1309. save: function(){
  1310. var tdContents = this.editContentNode.getElements("td.inforContent");
  1311. if (!this.nameInputNode.get("value") || !this.uniqueInputNode.get("value")){
  1312. this.explorer.app.notice(this.explorer.app.lp.inputUnitInfor, "error", this.explorer.propertyContentNode);
  1313. return false;
  1314. }
  1315. //this.data.genderType = gender;
  1316. //if (!this.uniqueInputNode.get("value")) this.data.unique = this.employeeInputNode.get("value");
  1317. this.content.propertyContentScrollNode.mask({
  1318. "style": {
  1319. "opacity": 0.7,
  1320. "background-color": "#999"
  1321. }
  1322. });
  1323. this.saveUnit(function(){
  1324. this.cancel( null,true );
  1325. this.content.propertyContentScrollNode.unmask();
  1326. }.bind(this), function(xhr, text, error){
  1327. var errorText = error;
  1328. if (xhr) errorText = xhr.responseText;
  1329. this.explorer.app.notice("request json error: "+errorText, "error");
  1330. this.content.propertyContentScrollNode.unmask();
  1331. }.bind(this));
  1332. },
  1333. saveUnit: function(callback, cancel){
  1334. var data = Object.clone(this.data);
  1335. data.name = this.nameInputNode.get("value");
  1336. data.unique = this.uniqueInputNode.get("value");
  1337. data.typeList = (this.typeListInputNode.get("value")) ? this.typeListInputNode.get("value").split(/,\s*/g) : [];
  1338. data.shortName = this.shortNameInputNode.get("value");
  1339. data.description = this.descriptionInputNode.get("value");
  1340. data.orderNumber = this.orderNumberInputNode.get("value");
  1341. delete data.oldSuperior;
  1342. delete data.oldControllerList;
  1343. //data.controllerList = (this.controllerListInputNode.get("value")) ? this.controllerListInputNode.get("value").split(/,\s*/g) : [];
  1344. this.explorer.actions.saveUnit(data, function(json){
  1345. Object.merge(this.data, data);
  1346. if (this.data.id){
  1347. this.data.id = json.data.id;
  1348. this.item.refresh();
  1349. if (callback) callback();
  1350. }else{
  1351. this.explorer.actions.getUnit(function(json){
  1352. this.data = Object.merge(this.data, json.data);
  1353. this.item.data = this.data;
  1354. this.item.refresh();
  1355. if (this.item.parent) this.item.parent.subUnits.push(this.item);
  1356. if (callback) callback();
  1357. }.bind(this), null, json.data.id);
  1358. }
  1359. }.bind(this), function(xhr, text, error){
  1360. if (cancel) cancel(xhr, text, error);
  1361. }.bind(this));
  1362. },
  1363. cancel: function( ev, flag ){
  1364. if (this.data.id){
  1365. var tdContents = this.editContentNode.getElements("td.inforContent");
  1366. tdContents[0].setStyles(this.style.baseInforContentNode).set("text", this.data.name || "");
  1367. tdContents[1].setStyles(this.style.baseInforContentNode).set("text", this.data.unique || "");
  1368. tdContents[2].setStyles(this.style.baseInforContentNode).set("text", ((this.data.typeList.length) ? this.data.typeList.join(", "): ""));
  1369. tdContents[3].setStyles(this.style.baseInforContentNode).set("text", this.data.shortName || "");
  1370. tdContents[4].setStyles(this.style.baseInforContentNode).set("text", this.data.description || "");
  1371. //tdContents[5].setStyles(this.style.baseInforContentNode).set("text", ((this.data.controllerList.length) ? this.data.controllerList.join(", "): ""));
  1372. tdContents[5].setStyles(this.style.baseInforContentNode).empty();
  1373. tdContents[6].setStyles(this.style.baseInforContentNode).empty();
  1374. tdContents[7].setStyles(this.style.baseInforContentNode).set("text", this.data.orderNumber || "");
  1375. if( !flag ){
  1376. if (this.data.oldSuperior) this.data.superior = this.data.oldSuperior;
  1377. if (this.data.oldControllerList) this.data.controllerList = this.data.oldControllerList;
  1378. }
  1379. delete this.data.oldSuperior;
  1380. delete this.data.oldControllerList;
  1381. if (this.data.superior) new MWF.widget.O2Unit({"name": this.data.superior}, tdContents[6], {"style": "xform"});
  1382. if (this.data.controllerList){
  1383. this.data.controllerList.each(function(id){
  1384. new MWF.widget.O2Person({"name": id}, tdContents[5], {"style": "xform"});
  1385. }.bind(this));
  1386. }
  1387. this.mode = "read";
  1388. this.editNode.setStyle("display", "block");
  1389. this.saveNode.setStyle("display", "none");
  1390. this.cancelNode.setStyle("display", "none");
  1391. }else{
  1392. this.item.destroy();
  1393. }
  1394. if( this.tooltip ){
  1395. this.tooltip.destroy();
  1396. this.tooltip = null;
  1397. }
  1398. },
  1399. destroy: function(){
  1400. if( this.tooltip ){
  1401. this.tooltip.destroy();
  1402. this.tooltip = null;
  1403. }
  1404. this.node.empty();
  1405. this.node.destroy();
  1406. MWF.release(this);
  1407. }
  1408. });
  1409. MWF.xApplication.Org.UnitExplorer.UnitContent.UniqueTooltip = new Class({
  1410. Extends: MTooltips,
  1411. _getHtml : function(){
  1412. var html =
  1413. "<div item='containr' style='line-height:24px;'><div style='font-size: 14px;color:red;float:left; '>"+ this.lp.unitUniqueModifyNote +"</div></div>";
  1414. return html;
  1415. }
  1416. });