UnitExplorer.js 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346
  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. "lazy" : true,
  561. "canRemove": _self.data.control.allowEdit,
  562. "onRemove": function(O2Identity, e){
  563. _self.deleteDutyIdentity(_dutyData, e, O2Identity);
  564. }
  565. })
  566. }.bind(this));
  567. },
  568. "click": function(){
  569. //_self.explorer.openGroup(this.data, this.td);
  570. }
  571. }
  572. }],
  573. "onPostSave": function(item, id){
  574. if (!item.data.id){
  575. item.data.id = id;
  576. this.data.woUnitDutyList.push(item.data);
  577. }
  578. this.loadListCount();
  579. }.bind(this),
  580. "onPostDelete": function(delCount){
  581. if (this.dutyCountNode){
  582. var count = this.dutyCountNode.get("text").toInt()-delCount;
  583. this.dutyCountNode.set("text", count);
  584. }
  585. }.bind(this),
  586. });
  587. //this.dutyList.addItem = function(){this.addDuty();};
  588. this.dutyList.load([
  589. {"style": "width: 20%", "text": this.explorer.app.lp.dutyName},
  590. {"style": "", "text": this.explorer.app.lp.description},
  591. {"style": "width: 50%", "text": this.explorer.app.lp.dutyMembers}
  592. ]);
  593. this.data.woUnitDutyList.each(function(item){
  594. //this.attributes.push(new MWF.xApplication.Org.PersonExplorer.PersonAttribute(this.attributeTabContentNode.getElement("table").getFirst(), item, this, this.explorer.css.list));
  595. this.dutyList.push(item);
  596. }.bind(this));
  597. },
  598. editDutyIdentity: function(dutyData, contentNode){
  599. var _self = this;
  600. MWF.xDesktop.requireApp("Selector", "Identity", function(){
  601. var selector = new MWF.xApplication.Selector.Identity(this.explorer.app.content,{
  602. "values": dutyData.identityList,
  603. "onComplete": function(items){
  604. var woIdentityList = [];
  605. var identityList = [];
  606. contentNode.empty();
  607. items.each(function(item, i){
  608. woIdentityList.push(item.data);
  609. identityList.push(item.data.id);
  610. new MWF.widget.O2Identity(item.data, contentNode, {
  611. "canRemove": true,
  612. "onRemove": function(O2Identity, e){
  613. _self.deleteDutyIdentity(dutyData, e, O2Identity);
  614. }
  615. })
  616. }.bind(this));
  617. dutyData.identityList = identityList;
  618. dutyData.woIdentityList = woIdentityList;
  619. _self.saveDuty(dutyData);
  620. }.bind(this)
  621. });
  622. selector.load();
  623. }.bind(this));
  624. },
  625. deleteDutyIdentity: function(dutyData, e, O2Identity){
  626. var _self = this;
  627. var text = this.explorer.app.lp.deleteDutyIdentity.replace(/{duty}/g, dutyData.name);
  628. text = text.replace(/{identity}/g, O2Identity.data.name);
  629. this.explorer.app.confirm("warn", e, this.explorer.app.lp.deleteDutyIdentityTitle, text, "360", "170", function(){
  630. dutyData.identityList.erase(O2Identity.data.id);
  631. dutyData.woIdentityList = dutyData.woIdentityList.filter(function(a){
  632. return (O2Identity.data.id !== a.id);
  633. });
  634. _self.saveDuty(dutyData, function(){
  635. O2Identity.destroy();
  636. });
  637. this.close();
  638. }, function(){
  639. this.close();
  640. });
  641. },
  642. saveDuty: function(data, callback){
  643. this.propertyContentScrollNode.mask({
  644. "style": {
  645. "opacity": 0.7,
  646. "background-color": "#999"
  647. }
  648. });
  649. this.explorer.actions.saveUnitduty(data, function(){
  650. this.propertyContentScrollNode.unmask();
  651. if (callback) callback();
  652. }.bind(this), function(xhr, text, error){
  653. var errorText = error;
  654. if (xhr) errorText = xhr.responseText;
  655. this.explorer.app.notice("request json error: "+errorText, "error");
  656. this.content.propertyContentScrollNode.unmask();
  657. }.bind(this));
  658. },
  659. _listAttributes: function(){
  660. this.attributeList = new MWF.xApplication.Org.List(this.attributeContentNode, this, {
  661. "action": this.data.control.allowEdit,
  662. "saveAction": "saveUnitattribute",
  663. "deleteAction": "deleteUnitattribute",
  664. "data": {
  665. "description":"",
  666. "name": "",
  667. "unique": "",
  668. "unit": this.data.id,
  669. "orderNumber": "",
  670. "attributeList": []
  671. },
  672. "attr": ["name", {
  673. "get": function(){return this.attributeList.join(",")},
  674. "set": function(value){this.attributeList = value.split(/,\s*/g)}
  675. }, "description"],
  676. "onPostSave": function(item, id){
  677. if (!item.data.id){
  678. item.data.id = id;
  679. this.data.woUnitAttributeList.push(item.data);
  680. }
  681. this.loadListCount();
  682. }.bind(this),
  683. "onPostDelete": function(delCount){
  684. if (this.attributeCountNode){
  685. var count = this.attributeCountNode.get("text").toInt()-delCount;
  686. this.attributeCountNode.set("text", count);
  687. }
  688. }.bind(this),
  689. });
  690. this.attributeList.load([
  691. {"style": "width: 20%", "text": this.explorer.app.lp.attributeName},
  692. {"style": "width: 45%", "text": this.explorer.app.lp.attributeValue},
  693. {"style": "", "text": this.explorer.app.lp.description}
  694. ]);
  695. this.data.woUnitAttributeList.each(function(item){
  696. //this.attributes.push(new MWF.xApplication.Org.PersonExplorer.PersonAttribute(this.attributeTabContentNode.getElement("table").getFirst(), item, this, this.explorer.css.list));
  697. this.attributeList.push(item);
  698. }.bind(this));
  699. },
  700. _listIdentityMembers: function(){
  701. var _self = this;
  702. this.identityMemberList = new MWF.xApplication.Org.List(this.personMemberContentNode, this, {
  703. "action": this.data.control.allowEdit,
  704. "canEdit": false,
  705. "deleteAction": "deleteIdentity",
  706. "deleteItemTitle": this.explorer.app.lp.deleteIdentityMemeberTitle,
  707. "deleteItemText": this.explorer.app.lp.deleteIdentityMemeber,
  708. "data": {},
  709. "attr": [{
  710. "getHtml": function(){
  711. var src = _self.explorer.actions.getPersonIcon(this.woPerson.id);
  712. return "<div style='width:24px; height:24px;''><img style='width:24px; height:24px; border-radius:12px; border: 0' src='"+src+"'/></div>";
  713. },
  714. "set": function(){}
  715. }, {
  716. "get": function(){return this.woPerson.name}
  717. }, {
  718. "get": function(){return this.woPerson.employee}
  719. }, {
  720. "get": function(){return this.woPerson.mobile}
  721. }, {
  722. "get": function(){return this.woPerson.mail}
  723. }, {
  724. "getHtml": function(){
  725. return "<div style='width:24px; height:24px; background:url(../x_component_Org/$Explorer/"+
  726. _self.explorer.app.options.style+"/icon/open.png) center center no-repeat'></div>";
  727. },
  728. "events": {
  729. "click": function(){
  730. _self.explorer.openPerson(this.data.woPerson, this.td);
  731. }
  732. }
  733. }, {
  734. "getHtml": function(){
  735. return "<div style='-webkit-user-select: none; -moz-user-select: none; width:24px; height:24px; cursor: move; background:url(../x_component_Org/$Explorer/"+
  736. _self.explorer.app.options.style+"/icon/move.png) center center no-repeat'></div>";
  737. },
  738. "events": {
  739. "selectstart": function(e){e.stopPropagation(); e.preventDefault();return false;},
  740. "touchstart": function(e){_self.startOrder(this.item, this.td, e)},
  741. "mousedown": function(e){_self.startOrder(this.item, this.td, e)}
  742. }
  743. }],
  744. "onPostDelete": function(delCount){
  745. if (this.identityCountNode){
  746. var count = this.identityCountNode.get("text").toInt()-delCount;
  747. this.identityCountNode.set("text", count);
  748. }
  749. }.bind(this)
  750. });
  751. this.identityMemberList.addItem = this.addPersonMember.bind(this);
  752. this.identityMemberList.load([
  753. {"style": "width: 30px", "text": ""},
  754. {"style": "width: 20%", "text": this.explorer.app.lp.personName},
  755. {"style": "", "text": this.explorer.app.lp.personEmployee},
  756. {"style": "", "text": this.explorer.app.lp.personMobile},
  757. {"style": "", "text": this.explorer.app.lp.personMail},
  758. {"style": "width: 10px", "text": ""},
  759. {"style": "width: 10px", "text": ""}
  760. ]);
  761. this.data.woSubDirectIdentityList.each(function(id){
  762. var item = this.identityMemberList.push(id);
  763. }.bind(this));
  764. },
  765. startOrder: function(item, td, e){
  766. var tr = td.getParent("tr");
  767. var table = tr.getParent("table");
  768. var div = td.getFirst("div");
  769. var size = tr.getSize();
  770. var titleTr = table.getElement("tr");
  771. var moveNode = new Element("table", {"styles": {
  772. "opacity": 0.7,
  773. "border": "1px dashed #999",
  774. "z-index": 10000,
  775. "width": size.x,
  776. "height": size.y,
  777. "background-color": "#CCC",
  778. "position": "absolute"
  779. }}).inject(this.explorer.app.content);
  780. var moveNodeTr = tr.clone().inject(moveNode);
  781. var moveTds = moveNodeTr.getElements("td");
  782. titleTr.getElements("th").each(function(cell, i){
  783. moveTds[i].setStyle("width", ""+cell.getSize().x+"px");
  784. });
  785. moveNode.position({
  786. relativeTo: tr,
  787. position: 'upperLeft',
  788. edge: 'upperLeft'
  789. });
  790. div.setStyle("display", "none");
  791. var nextData = {};
  792. var ntr = tr.getNext("tr");
  793. if (ntr) nextData = ntr.retrieve("data");
  794. if (!nextData) nextData={};
  795. var drag = new Drag.Move(moveNode, {
  796. "container": table,
  797. "droppables": table.getElements("tr").erase(tr),
  798. "preventDefault": true,
  799. "stopPropagation": true,
  800. "onStart": function(){
  801. tr.setStyles({
  802. "display": "none",
  803. "background-color": "#dff3fc"
  804. });
  805. }.bind(this),
  806. "onEnter": function(element, droppable){
  807. tr.inject(droppable, "after");
  808. droppable.setStyles({"background": "#fcf8f1"});
  809. tr.setStyles({"display": "table-row"});
  810. element.setStyles({"display": "none"});
  811. var nextTr = tr.getNext("tr");
  812. if (nextTr){
  813. nextData = nextTr.retrieve("data");
  814. }else{
  815. nextData={};
  816. }
  817. if (!nextData) nextData={};
  818. },
  819. "onLeave": function(element, droppable){
  820. droppable.setStyles({"background": "transparent "});
  821. tr.setStyles({"display": "none"});
  822. element.setStyles({"display": "block"});
  823. },
  824. "onDrop": function(dragging, droppable, e){
  825. var nextTr = tr.getNext("tr");
  826. if (nextTr){
  827. nextData = nextTr.retrieve("data");
  828. }else{
  829. nextData={};
  830. }
  831. if (!nextData) nextData={};
  832. moveNode.destroy();
  833. droppable.setStyles({"background": "transparent "});
  834. tr.setStyles({"background": "transparent "});
  835. this.explorer.actions.orderIdentity(item.data.id, nextData.id || "(0)", function(){});
  836. div.setStyle("display", "block");
  837. }.bind(this),
  838. "onCancel": function(dragging){
  839. dragging.destroy();
  840. drag = null;
  841. div.setStyle("display", "block");
  842. }
  843. });
  844. drag.start(e);
  845. // var moveNode = new Element("div", {"styles": {
  846. // "opacity": 0.7,
  847. // "border": "1px dashed #999",
  848. // "z-index": 10000,
  849. // "width": size.x,
  850. // "height": size.y,
  851. // "background-color": "#CCC",
  852. // "position": "absolute"
  853. // }}).inject(this.explorer.app.content);
  854. // moveNode.setStyles({
  855. // "opacity": 0.7,
  856. // "border": "1px dashed #999",
  857. // "z-index": 10000,
  858. // "width": size.x,
  859. // "height": size.y,
  860. // "background-color": "#CCC",
  861. // "position": "absolute"
  862. // });
  863. },
  864. addPersonMember: function(){
  865. this.checkSaveBaseInfor(function(){
  866. MWF.xDesktop.requireApp("Selector", "Person", function(){
  867. var selector = new MWF.xApplication.Selector.Person(this.explorer.app.content,{
  868. "values": [],
  869. "onComplete": function(items){
  870. var data = {
  871. "description": "",
  872. "name": "",
  873. "unique": "",
  874. "person": "",
  875. "department": "",
  876. "unit": this.data.id,
  877. "orderNumber": ""
  878. };
  879. items.each(function(item){
  880. var idData = Object.clone(data);
  881. idData.name = item.data.name;
  882. idData.person = item.data.id;
  883. this.explorer.actions.saveIdentity(idData, function(d){
  884. this.explorer.actions.getIdentity(function(id){
  885. this.data.woSubDirectIdentityList.push(id.data);
  886. this.identityMemberList.push(id.data);
  887. this.loadListCount();
  888. }.bind(this), null, d.data.id);
  889. }.bind(this));
  890. }.bind(this));
  891. }.bind(this)
  892. });
  893. selector.load();
  894. }.bind(this));
  895. }.bind(this));
  896. },
  897. checkSaveBaseInfor: function(callback){
  898. if (!this.data.id){
  899. if (this.baseInfor){
  900. if (this.baseInfor.mode==="edit") this.baseInfor.save(function(){
  901. if (callback) callback();
  902. }.bind(this));
  903. }
  904. }else{
  905. if (callback) callback();
  906. }
  907. }
  908. });
  909. MWF.xApplication.Org.UnitExplorer.UnitContent.TitleInfor = new Class({
  910. Extends: MWF.xApplication.Org.$Explorer.ItemContent.TitleInfor,
  911. _getStyle: function(){
  912. var css = Object.clone(this.item.style.person);
  913. return Object.merge(css, this.item.style.role);
  914. },
  915. _getIcon: function(){
  916. return "../x_component_Org/$Explorer/default/icon/unit70.png";
  917. },
  918. setBackground: function(){
  919. this.titleBgNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/unit_bg_bg.png)");
  920. this.titleNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/unit_bg.png)");
  921. },
  922. loadRightInfor: function(){
  923. //var text = this.data.name+((this.data.unique) ? "("+this.data.unique+")" : "");
  924. var text = this.data.name;
  925. if (!this.nameNode) this.nameNode = new Element("div", {"styles": this.style.titleInforNameNode}).inject(this.titleInforRightNode);
  926. if (!this.signatureNode) this.signatureNode = new Element("div", {"styles": this.style.titleInforSignatureNode}).inject(this.titleInforRightNode);
  927. this.nameNode.set("text", text);
  928. this.signatureNode.set("text", (this.data.levelName || "" ));
  929. }
  930. });
  931. MWF.xApplication.Org.UnitExplorer.UnitContent.BottomInfor = new Class({
  932. Extends: MWF.xApplication.Org.$Explorer.ItemContent.BottomInfor,
  933. addInforList: function(){
  934. var text = this.explorer.app.lp.unitReadDn.replace(/{dn}/g, (this.data.distinguishedName || " "));
  935. this.addInfor(text);
  936. text = this.explorer.app.lp.unitReadLevel.replace(/{level}/g, (this.data.level || " "));
  937. text = text.replace(/{levelName}/g, (this.data.levelName || " "));
  938. this.addInfor(text);
  939. text = this.explorer.app.lp.unitReadCreate.replace(/{date}/g, (this.data.createTime || " "));
  940. text = text.replace(/{date2}/g, (this.data.updateTime || " "));
  941. this.addInfor(text);
  942. }
  943. });
  944. MWF.xApplication.Org.UnitExplorer.UnitContent.BaseInfor = new Class({
  945. initialize: function(content){
  946. this.content = content;
  947. this.item = content.item;
  948. this.data = this.item.data;
  949. this.explorer = this.item.explorer;
  950. this.contentNode = this.content.baseContentNode;
  951. this.style = this.item.style.person;
  952. this.attributes = [];
  953. this.mode = "read";
  954. this.load();
  955. },
  956. load: function(){
  957. this.node = new Element("div", {"styles": this.style.baseContentNode}).inject(this.contentNode);
  958. this.editContentNode = new Element("div", {"styles": this.style.baseEditNode}).inject(this.node);
  959. this.editContentNode.set("html", this.getContentHtml());
  960. var n = this.editContentNode.getElement(".infor_name");
  961. if (n) n.set("text", this.data.name || "");
  962. var n = this.editContentNode.getElement(".infor_unique");
  963. if (n) n.set("text", this.data.unique || "");
  964. var n = this.editContentNode.getElement(".infor_type");
  965. if (n) n.set("text", this.data.typeList.join(", ") || "");
  966. var n = this.editContentNode.getElement(".infor_shortName");
  967. if (n) n.set("text", this.data.shortName || "");
  968. var n = this.editContentNode.getElement(".infor_description");
  969. if (n) n.set("text", this.data.description || "");
  970. var n = this.editContentNode.getElement(".infor_orderNumber");
  971. if (n) n.set("text", this.data.orderNumber || "");
  972. this.editContentNode.getElements("td.inforTitle").setStyles(this.style.baseInforTitleNode);
  973. this.editContentNode.getElements("td.inforContent").setStyles(this.style.baseInforContentNode);
  974. this.editContentNode.getElements("td.inforAction").setStyles(this.style.baseInforActionNode);
  975. var tdContents = this.editContentNode.getElements("td.inforContent");
  976. if (this.data.control.allowEdit){
  977. if (this.data.controllerList){
  978. this.data.controllerList.each(function(id){
  979. new MWF.widget.O2Person({"name": id}, tdContents[5], {"style": "xform"});
  980. }.bind(this));
  981. }
  982. if (this.data.superior) new MWF.widget.O2Unit({"name": this.data.superior}, tdContents[6], {"style": "xform"});
  983. }
  984. this.loadAction();
  985. },
  986. getContentHtml: function(){
  987. debugger;
  988. var html = "<table width='100%' cellpadding='3px' cellspacing='5px'>";
  989. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.unitName+":</td><td class='inforContent infor_name'></td>";
  990. if (this.data.control.allowEdit) html += "<td class='inforTitle'>"+this.explorer.app.lp.unitUnique+":</td><td class='inforContent infor_unique'></td>";
  991. html += "</tr><tr><td class='inforTitle'>"+this.explorer.app.lp.unitTypeList+":</td><td class='inforContent infor_type'></td>" +
  992. "<td class='inforTitle'>"+this.explorer.app.lp.unitShortName+":</td><td class='inforContent infor_shortName'></td></tr>";
  993. // html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.unitLevel+":</td><td class='inforContent'>"+this.data.level+"</td>" +
  994. // "<td class='inforTitle'>"+this.explorer.app.lp.unitLevelName+":</td><td class='inforContent'>"+(this.data.levelName || "")+"</td></tr>";
  995. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.unitDescription+":</td><td colspan='3' class='inforContent infor_description'></td>";
  996. if (this.data.control.allowEdit){
  997. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.unitControllerList+":</td><td class='inforContent'></td>" +
  998. "<td class='inforTitle'>"+this.explorer.app.lp.unitSuperUnit+":</td><td class='inforContent'></td></tr>";
  999. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.orderNumber+":</td><td colspan='3' class='inforContent infor_orderNumber'></td></tr>";
  1000. }
  1001. html += "<tr><td colspan='4' class='inforAction'></td></tr>";
  1002. //this.baseInforRightNode.set("html", html);
  1003. return html;
  1004. },
  1005. loadAction: function(){
  1006. //this.explorer.app.lp.edit
  1007. var actionAreas = this.editContentNode.getElements("td");
  1008. var actionArea = actionAreas[actionAreas.length-1];
  1009. if (this.data.control.allowEdit){
  1010. this.baseInforEditActionAreaNode = new Element("div", {"styles": this.style.baseInforEditActionAreaNode}).inject(actionArea);
  1011. this.editNode = new Element("div", {"styles": this.style.actionEditNode, "text": this.explorer.app.lp.editUnit}).inject(this.baseInforEditActionAreaNode);
  1012. this.saveNode = new Element("div", {"styles": this.style.actionSaveNode, "text": this.explorer.app.lp.saveUnit}).inject(this.baseInforEditActionAreaNode);
  1013. this.cancelNode = new Element("div", {"styles": this.style.actionCancelNode, "text": this.explorer.app.lp.cancel}).inject(this.baseInforEditActionAreaNode);
  1014. this.editNode.setStyle("display", "block");
  1015. this.editNode.addEvent("click", this.edit.bind(this));
  1016. this.saveNode.addEvent("click", this.save.bind(this));
  1017. this.cancelNode.addEvent("click", this.cancel.bind(this));
  1018. }else{
  1019. }
  1020. },
  1021. edit: function(){
  1022. var tdContents = this.editContentNode.getElements("td.inforContent");
  1023. tdContents[0].setStyles(this.style.baseInforContentNode_edit).empty();
  1024. this.nameInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[0]);
  1025. this.nameInputNode.set("value", (this.data.name));
  1026. tdContents[1].setStyles(this.style.baseInforContentNode_edit).empty();
  1027. this.uniqueInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[1]);
  1028. this.uniqueInputNode.set("value", (this.data.unique));
  1029. tdContents[2].setStyles(this.style.baseInforContentNode_edit).empty();
  1030. this.typeListInputNode = new Element("input", {"styles": this.style.inputNode_type}).inject(tdContents[2]);
  1031. this.typeListInputNode.set("value", ((this.data.typeList.length) ? this.data.typeList.join(", "): ""));
  1032. this.loadUnitTypeSelect();
  1033. tdContents[3].setStyles(this.style.baseInforContentNode_edit).empty();
  1034. this.shortNameInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[3]);
  1035. this.shortNameInputNode.set("value", (this.data.shortName || ""));
  1036. tdContents[4].setStyles(this.style.baseInforContentNode_edit).empty();
  1037. this.descriptionInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[4]);
  1038. this.descriptionInputNode.set("value", (this.data.description || ""));
  1039. tdContents[5].setStyles(this.style.baseInforContentNode_edit).empty();
  1040. this.controllerListInputNode = new Element("div", {"styles": this.style.inputNode_person}).inject(tdContents[5]);
  1041. tdContents[6].setStyles(this.style.baseInforContentNode_edit).empty();
  1042. this.superUnitInputNode = new Element("div", {"styles": this.style.inputNode_person}).inject(tdContents[6]);
  1043. tdContents[7].setStyles(this.style.baseInforContentNode_edit).empty();
  1044. this.orderNumberInputNode = new Element("input", {"styles": this.style.inputNode, "type":"number"}).inject(tdContents[7]);
  1045. this.orderNumberInputNode.set("value", (this.data.orderNumber || ""));
  1046. //this.controllerListInputNode.set("value", ((this.data.controllerList) ? this.data.controllerList.join(", ") : ""));
  1047. if (this.data.superior) new MWF.widget.O2Unit({"name": this.data.superior}, this.superUnitInputNode, {"style": "xform"});
  1048. this.superUnitInputNode.addEvent("click", function(){
  1049. MWF.xDesktop.requireApp("Selector", "package", function(){
  1050. var options = {
  1051. "type": "unit",
  1052. "values": [this.data.superior] || [],
  1053. "count": 1,
  1054. "onComplete": function(items){
  1055. this.superUnitInputNode.empty();
  1056. this.data.oldSuperior = this.data.superior;
  1057. if (items.length){
  1058. this.data.superior = items[0].data.id;
  1059. new MWF.widget.O2Unit({"name": this.data.superior}, this.superUnitInputNode, {"style": "xform"})
  1060. }else{
  1061. this.data.superior = "";
  1062. }
  1063. }.bind(this)
  1064. };
  1065. var selector = new MWF.O2Selector(this.explorer.app.content, options);
  1066. }.bind(this));
  1067. }.bind(this));
  1068. if (this.data.controllerList){
  1069. this.data.controllerList.each(function(id){
  1070. new MWF.widget.O2Person({"name": id}, this.controllerListInputNode, {"style": "xform"});
  1071. }.bind(this));
  1072. }
  1073. this.controllerListInputNode.addEvent("click", function(){
  1074. MWF.xDesktop.requireApp("Selector", "package", function(){
  1075. var options = {
  1076. "type": "person",
  1077. "values": this.data.controllerList || [],
  1078. "count": 0,
  1079. "onComplete": function(items){
  1080. this.data.oldControllerList = this.data.controllerList;
  1081. var controllerList = [];
  1082. this.controllerListInputNode.empty();
  1083. items.each(function(item){
  1084. controllerList.push(item.data.id);
  1085. new MWF.widget.O2Person(item.data, this.controllerListInputNode, {"style": "xform"});
  1086. }.bind(this));
  1087. this.data.controllerList = controllerList;
  1088. }.bind(this)
  1089. };
  1090. var selector = new MWF.O2Selector(this.explorer.app.content, options);
  1091. }.bind(this));
  1092. }.bind(this));
  1093. var _self = this;
  1094. this.editContentNode.getElements("input").addEvents({
  1095. "focus": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_focus);}},
  1096. "blur": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_blur);}}
  1097. });
  1098. this.mode = "edit";
  1099. this.editNode.setStyle("display", "none");
  1100. this.saveNode.setStyle("display", "block");
  1101. this.cancelNode.setStyle("display", "block");
  1102. },
  1103. loadUnitTypeSelect: function(){
  1104. if (this.typeListInputNode){
  1105. this.typeListInputNode.addEvents({
  1106. "blur": function(){this.hideTypeSelectNode();}.bind(this),
  1107. "click": function(){this.showTypeSelectNode();}.bind(this),
  1108. "focus": function(){this.showTypeSelectNode();}.bind(this)
  1109. });
  1110. }
  1111. },
  1112. hideTypeSelectNode: function(){
  1113. if (this.typeSelectNode) this.typeSelectNode.destroy();
  1114. this.typeSelectNode = null;
  1115. },
  1116. showTypeSelectNode: function(){
  1117. if (!this.typeSelectNode){
  1118. this.typeSelectNode = new Element("div", {"styles": this.style.typeSelectNode}).inject(this.typeListInputNode, "after");
  1119. var size = this.typeListInputNode.getSize();
  1120. var width = size.x-3;
  1121. this.typeSelectNode.setStyle("width", ""+width+"px");
  1122. this.typeSelectNode.position({
  1123. "relativeTo": this.typeListInputNode,
  1124. "position": 'bottomLeft',
  1125. "edge": 'upperLeft',
  1126. "offset": {"x": 1, "y": -3}
  1127. });
  1128. this.explorer.actions.listUnitType(function(json){
  1129. var count = json.data.valueList.length;
  1130. var height = (count*30);
  1131. this.typeSelectNode.setStyle("height", ""+height+"px");
  1132. json.data.valueList.each(function(t, i){
  1133. this.createTypeSelectItem(t, i);
  1134. }.bind(this));
  1135. }.bind(this));
  1136. }
  1137. },
  1138. createTypeSelectItem: function(text, i){
  1139. var typeSelectItemNode = new Element("div", {"styles": this.style.typeSelectItemNode}).inject(this.typeSelectNode);
  1140. if ((i % 2)===0) typeSelectItemNode.setStyle("background", "#f4f9ff");
  1141. var iconNode = new Element("div", {"styles": this.style.typeSelectItemIconNode}).inject(typeSelectItemNode);
  1142. var textNode = new Element("div", {"styles": this.style.typeSelectItemTextNode}).inject(typeSelectItemNode);
  1143. textNode.set("text", text);
  1144. var _self = this;
  1145. typeSelectItemNode.addEvents({
  1146. "mouseover": function(){this.setStyle("background-color", "#fef5e7");},
  1147. "mouseout": function(){this.setStyle("background", "#ffffff"); if ((i % 2)===0) this.setStyle("background", "#f4f9ff");},
  1148. "mousedown": function(){
  1149. _self.typeListInputNode.set("value", this.get("text"));
  1150. }
  1151. });
  1152. },
  1153. save: function(){
  1154. var tdContents = this.editContentNode.getElements("td.inforContent");
  1155. if (!this.nameInputNode.get("value")){
  1156. this.explorer.app.notice(this.explorer.app.lp.inputUnitInfor, "error", this.explorer.propertyContentNode);
  1157. return false;
  1158. }
  1159. //this.data.genderType = gender;
  1160. //if (!this.uniqueInputNode.get("value")) this.data.unique = this.employeeInputNode.get("value");
  1161. this.content.propertyContentScrollNode.mask({
  1162. "style": {
  1163. "opacity": 0.7,
  1164. "background-color": "#999"
  1165. }
  1166. });
  1167. this.saveUnit(function(){
  1168. this.cancel();
  1169. this.content.propertyContentScrollNode.unmask();
  1170. }.bind(this), function(xhr, text, error){
  1171. var errorText = error;
  1172. if (xhr) errorText = xhr.responseText;
  1173. this.explorer.app.notice("request json error: "+errorText, "error");
  1174. this.content.propertyContentScrollNode.unmask();
  1175. }.bind(this));
  1176. },
  1177. saveUnit: function(callback, cancel){
  1178. var data = Object.clone(this.data);
  1179. data.name = this.nameInputNode.get("value");
  1180. data.unique = this.uniqueInputNode.get("value");
  1181. data.typeList = (this.typeListInputNode.get("value")) ? this.typeListInputNode.get("value").split(/,\s*/g) : [];
  1182. data.shortName = this.shortNameInputNode.get("value");
  1183. data.description = this.descriptionInputNode.get("value");
  1184. data.orderNumber = this.orderNumberInputNode.get("value");
  1185. delete data.oldSuperior;
  1186. delete data.oldControllerList;
  1187. //data.controllerList = (this.controllerListInputNode.get("value")) ? this.controllerListInputNode.get("value").split(/,\s*/g) : [];
  1188. this.explorer.actions.saveUnit(data, function(json){
  1189. Object.merge(this.data, data);
  1190. if (this.data.id){
  1191. this.data.id = json.data.id;
  1192. this.item.refresh();
  1193. if (callback) callback();
  1194. }else{
  1195. this.explorer.actions.getUnit(function(json){
  1196. this.data = Object.merge(this.data, json.data);
  1197. this.item.data = this.data;
  1198. this.item.refresh();
  1199. if (this.item.parent) this.item.parent.subUnits.push(this.item);
  1200. if (callback) callback();
  1201. }.bind(this), null, json.data.id);
  1202. }
  1203. }.bind(this), function(xhr, text, error){
  1204. if (cancel) cancel(xhr, text, error);
  1205. }.bind(this));
  1206. },
  1207. cancel: function(){
  1208. if (this.data.id){
  1209. var tdContents = this.editContentNode.getElements("td.inforContent");
  1210. tdContents[0].setStyles(this.style.baseInforContentNode).set("text", this.data.name || "");
  1211. tdContents[1].setStyles(this.style.baseInforContentNode).set("text", this.data.unique || "");
  1212. tdContents[2].setStyles(this.style.baseInforContentNode).set("text", ((this.data.typeList.length) ? this.data.typeList.join(", "): ""));
  1213. tdContents[3].setStyles(this.style.baseInforContentNode).set("text", this.data.shortName || "");
  1214. tdContents[4].setStyles(this.style.baseInforContentNode).set("text", this.data.description || "");
  1215. //tdContents[5].setStyles(this.style.baseInforContentNode).set("text", ((this.data.controllerList.length) ? this.data.controllerList.join(", "): ""));
  1216. tdContents[5].setStyles(this.style.baseInforContentNode).empty();
  1217. tdContents[6].setStyles(this.style.baseInforContentNode).empty();
  1218. tdContents[7].setStyles(this.style.baseInforContentNode).set("text", this.data.orderNumber || "");
  1219. if (this.data.oldSuperior) this.data.superior = this.data.oldSuperior;
  1220. if (this.data.oldControllerList) this.data.controllerList = this.data.oldControllerList;
  1221. delete this.data.oldSuperior;
  1222. delete this.data.oldControllerList;
  1223. if (this.data.superior) new MWF.widget.O2Unit({"name": this.data.superior}, tdContents[6], {"style": "xform"});
  1224. if (this.data.controllerList){
  1225. this.data.controllerList.each(function(id){
  1226. new MWF.widget.O2Person({"name": id}, tdContents[5], {"style": "xform"});
  1227. }.bind(this));
  1228. }
  1229. this.mode = "read";
  1230. this.editNode.setStyle("display", "block");
  1231. this.saveNode.setStyle("display", "none");
  1232. this.cancelNode.setStyle("display", "none");
  1233. }else{
  1234. this.item.destroy();
  1235. }
  1236. },
  1237. destroy: function(){
  1238. this.node.empty();
  1239. this.node.destroy();
  1240. MWF.release(this);
  1241. }
  1242. });