UnitExplorer.js 59 KB

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