UnitExplorer.js 59 KB

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