UnitExplorer.js 61 KB

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