$Explorer.js 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  1. MWF.require("MWF.widget.Tab", null, false);
  2. MWF.xDesktop.requireApp("Org", "List", null, false);
  3. MWF.xApplication.Org.$Explorer = new Class({
  4. Extends: MWF.widget.Common,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default"
  8. },
  9. _loadPath: function(){
  10. this.path = "../x_component_Org/$Explorer/";
  11. this.cssPath = "../x_component_Org/$Explorer/"+this.options.style+"/css.wcss";
  12. },
  13. initialize: function(node, actions, options){
  14. this.setOptions(options);
  15. this._loadPath();
  16. this._loadCss();
  17. this.actions = actions;
  18. this.node = $(node);
  19. this.loaddingElement = false;
  20. this.elements = [];
  21. this.isElementLoaded = false;
  22. this.loadElementQueue = 0;
  23. this.deleteElements = [];
  24. },
  25. _loadLp: function(){
  26. this.options.lp = {
  27. "elementLoaded": this.app.lp.personLoaded,
  28. "search": this.app.lp.search,
  29. "searchText": this.app.lp.searchText,
  30. "elementSave": this.app.lp.personSave,
  31. "deleteElements": this.app.lp.deletePersons,
  32. "deleteElementsCancel": this.app.lp.deleteElementsCancel,
  33. "deleteElementsTitle": this.app.lp.deletePersonsTitle,
  34. "deleteElementsConfirm": this.app.lp.deletePersonsConfirm,
  35. "elementBaseText": this.app.lp.personBaseText,
  36. "elementName": this.app.lp.personName,
  37. "noSignature": this.app.lp.noSignature,
  38. "edit": this.app.lp.edit,
  39. "cancel": this.app.lp.cancel,
  40. "save": this.app.lp.save,
  41. "add": this.app.lp.add
  42. }
  43. },
  44. clear: function(){
  45. this.loaddingElement = false;
  46. this.isElementLoaded = false;
  47. this.loadElementQueue = 0;
  48. this.page = 0;
  49. this.listNode.empty();
  50. },
  51. load: function(){
  52. this._loadLp();
  53. this.loadLayout();
  54. this.loadList();
  55. },
  56. loadLayout: function(){
  57. this.listAreaNode = new Element("div", {"styles": this.css.listAreaNode}).inject(this.node);
  58. this.propertyAreaNode = new Element("div", {"styles": this.css.propertyAreaNode}).inject(this.node);
  59. this.resizeBarNode = new Element("div", {"styles": this.css.resizeBarNode}).inject(this.propertyAreaNode);
  60. this.propertyNode = new Element("div", {"styles": this.css.propertyNode}).inject(this.propertyAreaNode);
  61. this.propertyTitleNode = new Element("div", {"styles": this.css.propertyTitleNode}).inject(this.propertyNode);
  62. this.propertyContentNode = new Element("div", {"styles": this.css.propertyContentNode}).inject(this.propertyNode);
  63. this.propertyContentNode.setStyle("-webkit-user-select", "text");
  64. this.node.addEvent("selectstart", function(e){
  65. this.propertyContentNode.setStyle("-webkit-user-select", "text");
  66. }.bind(this));
  67. this.toolbarNode = new Element("div", {"styles": this.css.toolbarNode}).inject(this.listAreaNode);
  68. this.listScrollNode = new Element("div", {"styles": this.css.listScrollNode}).inject(this.listAreaNode);
  69. this.listNode = new Element("div", {"styles": this.css.listNode}).inject(this.listScrollNode);
  70. this.loadToolbar();
  71. this.resizePropertyContentNodeFun = this.resizePropertyContentNode.bind(this);
  72. this.resizePropertyContentNodeFun();
  73. this.app.addEvent("resize", this.resizePropertyContentNodeFun);
  74. this.loadScroll();
  75. this.loadResize();
  76. },
  77. loadToolbar: function(){
  78. if (this._isActionManager()) {
  79. this.isEditor = true;
  80. this.addTopElementNode = new Element("div", {"styles": this.css.addTopGroupNode}).inject(this.toolbarNode);
  81. this.addTopElementNode.addEvent("click", function () {
  82. this.addTopElement();
  83. }.bind(this));
  84. }
  85. this.createSearchNode();
  86. this.loadPingyinArea();
  87. },
  88. loadPingyinArea: function(){
  89. this.pingyinAction = new Element("div", {"styles": this.css.pingyinAction}).inject(this.app.pingyinArea);
  90. this.pingyinAction.addEvent("click", function(e){
  91. if (!this.pingyinNode) this.createPingyinNode();
  92. if (this.pingyinMorph){
  93. if (!this.pingyinMorph.isRunning()){
  94. if (this.pingyinNode.getStyle("display")==="none"){
  95. this.showPingyin();
  96. }else{
  97. this.hidePingyin();
  98. }
  99. }
  100. }else{
  101. this.showPingyin();
  102. }
  103. }.bind(this));
  104. this.pingyinAction.addEvent("mousedown", function(e){e.stopPropagation();});
  105. this.hidePingyinFun = this.hidePingyin.bind(this);
  106. this.app.content.addEvent("mousedown", this.hidePingyinFun);
  107. this.removePingyinFun = this.removePingyin.bind(this);
  108. this.app.addEvent("queryClose", this.removePingyinFun);
  109. },
  110. removePingyin: function(){
  111. this.app.content.removeEvent("mousedown", this.hidePingyinFun);
  112. },
  113. hidePingyin: function(){
  114. if (this.pingyinNode){
  115. if (!this.pingyinMorph){
  116. this.pingyinMorph = new Fx.Morph(this.pingyinNode, {duration: 50, link: "chain"});
  117. }
  118. if (!this.pingyinMorph.isRunning()){
  119. if (this.pingyinNode.getStyle("display")!=="none"){
  120. this.pingyinMorph.start(this.css.pingyinNode).chain(function(){
  121. this.pingyinNode.setStyle("display", "none");
  122. }.bind(this));
  123. }
  124. }
  125. }
  126. },
  127. showPingyin: function(){
  128. this.resizePropertyContentNode();
  129. if (!this.pingyinMorph){
  130. this.pingyinMorph = new Fx.Morph(this.pingyinNode, {duration: 50, link: "chain"});
  131. }
  132. this.pingyinNode.setStyle("display", "block");
  133. this.pingyinMorph.start(this.css.pingyinNode_to).chain(function(){
  134. this.pingyinNode.setStyles(this.css.pingyinNode_to);
  135. }.bind(this));
  136. },
  137. setPingyinNodePosition: function(){
  138. this.pingyinNode.position({
  139. relativeTo: this.node,
  140. position: "leftTop",
  141. edge: "leftTop"
  142. });
  143. },
  144. createPingyinNode: function(){
  145. this.pingyinNode = new Element("div", {"styles": this.css.pingyinNode}).inject(this.node);
  146. this.pingyinNode.addEvent("mousedown", function(e){e.stopPropagation();});
  147. letters = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
  148. letters.each(function(l){
  149. var letterNode = new Element("div", {"styles": this.css.letterNode,"text": l}).inject(this.pingyinNode);
  150. letterNode.addEvents({
  151. "mouseover": function(e){
  152. e.target.setStyles(this.css.letterNode_over);
  153. }.bind(this),
  154. "mouseout": function(e){
  155. e.target.setStyles(this.css.letterNode);
  156. }.bind(this),
  157. "click": function(e){
  158. this.searchInputNode.set("value", e.target.get("text"));
  159. this.searchOrg();
  160. this.hidePingyin();
  161. }.bind(this)
  162. });
  163. }.bind(this));
  164. },
  165. addTopElement: function(){
  166. var isNewElement = true;
  167. if (this.currentItem) isNewElement = this.currentItem.unSelected();
  168. if (isNewElement){
  169. var newElementData = this._getAddElementData();
  170. var item = this._newElement(newElementData, this);
  171. item.load();
  172. item.selected();
  173. item.editBaseInfor();
  174. (new Fx.Scroll(this.listScrollNode)).toElementCenter(item.node);
  175. }else{
  176. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  177. }
  178. },
  179. createSearchNode: function(){
  180. this.searchNode = new Element("div", {"styles": this.css.searchNode}).inject(this.toolbarNode);
  181. this.searchButtonNode = new Element("div", {"styles": this.css.searchButtonNode,"title": this.options.lp.search}).inject(this.searchNode);
  182. this.searchButtonNode.addEvent("click", function(){this.searchOrg();}.bind(this));
  183. this.searchInputAreaNode = new Element("div", {"styles": this.css.searchInputAreaNode}).inject(this.searchNode);
  184. this.searchInputNode = new Element("input", {
  185. "type": "text",
  186. "value": this.options.lp.searchText,
  187. "styles": this.css.searchInputNode,
  188. //"x-webkit-speech": "1",
  189. "x-webkit-speech": "x-webkit-speech"
  190. }).inject(this.searchInputAreaNode);
  191. var _self = this;
  192. this.searchInputNode.addEvents({
  193. "focus": function(){if (this.value ===_self.options.lp.searchText) this.set("value", "");},
  194. "blur": function(){if (!this.value) this.set("value", _self.options.lp.searchText);},
  195. "keydown": function(e){
  196. if (e.code===13){
  197. this.searchOrg();
  198. e.preventDefault();
  199. }
  200. }.bind(this),
  201. "selectstart": function(e){e.preventDefault();},
  202. "change": function(){
  203. var key = this.searchInputNode.get("value");
  204. if (!key || key===this.options.lp.searchText) {
  205. if (this.currentItem){
  206. if (this.currentItem.unSelected()){
  207. this.clear();
  208. this.loadElements();
  209. }else{
  210. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  211. }
  212. }
  213. }
  214. }.bind(this)
  215. });
  216. // this.searchButtonNode.addEvent("click", function(){this.searchOrg();}.bind(this));
  217. },
  218. searchOrg: function(){
  219. debugger;
  220. var key = this.searchInputNode.get("value");
  221. var isSearchElement = true;
  222. this.searching = false;
  223. if (key){
  224. if (key!==this.options.lp.searchText){
  225. if (this.currentItem) isSearchElement = this.currentItem.unSelected();
  226. if (isSearchElement){
  227. this._listElementByKey(function(json){
  228. if (this.currentItem) this.currentItem.unSelected();
  229. this.clear();
  230. json.data.each(function(itemData){
  231. var item = this._newElement(itemData, this);
  232. item.load();
  233. }.bind(this));
  234. this.searching = true;
  235. }.bind(this), null, key);
  236. }else{
  237. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  238. }
  239. }else{
  240. if (this.currentItem) isSearchElement = this.currentItem.unSelected();
  241. if (isSearchElement){
  242. this.clear();
  243. this.reloadElements();
  244. }else{
  245. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  246. }
  247. }
  248. }else{
  249. if (this.currentItem) isSearchElement = this.currentItem.unSelected();
  250. if (isSearchElement){
  251. this.clear();
  252. this.reloadElements();
  253. }else{
  254. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  255. }
  256. }
  257. },
  258. resizePropertyContentNode: function(){
  259. var size = this.node.getSize();
  260. var tSize = this.propertyTitleNode.getSize();
  261. var mtt = this.propertyTitleNode.getStyle("margin-top").toFloat();
  262. var mbt = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  263. var mtc = this.propertyContentNode.getStyle("margin-top").toFloat();
  264. var mbc = this.propertyContentNode.getStyle("margin-bottom").toFloat();
  265. var height = size.y-tSize.y-mtt-mbt-mtc-mbc;
  266. this.propertyContentNode.setStyle("height", height);
  267. tSize = this.toolbarNode.getSize();
  268. mtt = this.toolbarNode.getStyle("margin-top").toFloat();
  269. mbt = this.toolbarNode.getStyle("margin-bottom").toFloat();
  270. mtc = this.toolbarNode.getStyle("margin-top").toFloat();
  271. mbc = this.toolbarNode.getStyle("margin-bottom").toFloat();
  272. height = size.y-tSize.y-mtt-mbt-mtc-mbc;
  273. this.listScrollNode.setStyle("height", ""+height+"px");
  274. if (this.pingyinNode){
  275. this.setPingyinNodePosition();
  276. this.pingyinNode.setStyle("height", ""+size.y+"px");
  277. }
  278. },
  279. loadScroll: function(){
  280. MWF.require("MWF.widget.ScrollBar", function(){
  281. var _self = this;
  282. new MWF.widget.ScrollBar(this.listScrollNode, {
  283. "style":"xApp_Organization_Explorer",
  284. "where": "before",
  285. "distance": 100,
  286. "friction": 4,
  287. "axis": {"x": false, "y": true},
  288. "onScroll": function(y){
  289. if( _self.searching )return;
  290. var scrollSize = _self.listScrollNode.getScrollSize();
  291. var clientSize = _self.listScrollNode.getSize();
  292. var scrollHeight = scrollSize.y-clientSize.y;
  293. if (y+200>scrollHeight) {
  294. if (!_self.isElementLoaded) _self.loadElements();
  295. }
  296. }
  297. });
  298. // new MWF.widget.ScrollBar(this.propertyContentNode, {
  299. // "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  300. // });
  301. }.bind(this));
  302. },
  303. loadResize: function(){
  304. this.propertyResize = new Drag(this.resizeBarNode,{
  305. "snap": 1,
  306. "onStart": function(el, e){
  307. var x = e.event.clientX;
  308. var y = e.event.clientY;
  309. el.store("position", {"x": x, "y": y});
  310. var size = this.listAreaNode.getSize();
  311. el.store("initialWidth", size.x);
  312. }.bind(this),
  313. "onDrag": function(el, e){
  314. var x = e.event.clientX;
  315. // var y = e.event.y;
  316. var bodySize = this.node.getSize();
  317. var position = el.retrieve("position");
  318. var initialWidth = el.retrieve("initialWidth").toFloat();
  319. var dx = position.x.toFloat()-x.toFloat();
  320. var width = initialWidth-dx;
  321. if (width> bodySize.x/1.5) width = bodySize.x/1.5;
  322. if (width<300) width = 300;
  323. this.listAreaNode.setStyle("width", width+1);
  324. this.propertyAreaNode.setStyle("margin-left", width);
  325. }.bind(this)
  326. });
  327. },
  328. getPageNodeCount: function(){
  329. if(this.pageNodeCount)return this.pageNodeCount;
  330. var size = this.listScrollNode.getSize();
  331. this.pageNodeCount = (size.y / 50).toInt() + 5;
  332. return this.pageNodeCount;
  333. },
  334. loadList: function(){
  335. this.loadElements();
  336. this.continueLoadFun = this.continueLoad.bind(this);
  337. this.app.addEvent("resize", this.continueLoadFun);
  338. },
  339. continueLoad: function(){
  340. if (this.elements.length<this.getPageNodeCount()){
  341. this.loadElements(true);
  342. }
  343. },
  344. reloadElements : function(){
  345. this.elements = [];
  346. this.clear();
  347. this.loadElements();
  348. },
  349. loadElements: function(addToNext){
  350. if (!this.isElementLoaded){
  351. if (!this.loaddingElement){
  352. this.loaddingElement = true;
  353. this.page = this.page ? (this.page+1) : 1;
  354. var count = this.getPageNodeCount();
  355. this._listElementNext(this.getLastLoadedElementId(), count, function(json){
  356. if (json.data.length){
  357. this.loadListContent(json.data);
  358. this.loaddingElement = false;
  359. if (json.data.length<count){
  360. this.isElementLoaded = true;
  361. this.app.notice(this.options.lp.elementLoaded, "ok", this.listScrollNode, {"x": "center", "y": "bottom"});
  362. }else{
  363. if (this.loadElementQueue>0){
  364. this.loadElementQueue--;
  365. this.loadElements();
  366. }
  367. }
  368. }else{
  369. if (!this.elements.length){
  370. //this.setNoGroupNoticeArea();
  371. }else{
  372. this.app.notice(this.options.lp.elementLoaded, "ok", this.listScrollNode, {"x": "center", "y": "bottom"});
  373. }
  374. this.isElementLoaded = true;
  375. this.loaddingElement = false;
  376. }
  377. }.bind(this), this.page);
  378. }else{
  379. if (addToNext) this.loadElementQueue++;
  380. }
  381. }
  382. },
  383. getLastLoadedElementId: function(){
  384. return (this.elements.length) ? this.elements[this.elements.length-1].data.id : "";
  385. },
  386. loadListContent: function(data){
  387. data.each(function(itemData, i){
  388. var item = this._newElement(itemData, this, i);
  389. this.elements.push(item);
  390. item.load();
  391. if (this.elements.length===1) item.selected();
  392. }.bind(this));
  393. },
  394. setNoElementNoticeArea: function(){
  395. //没有数据时的提示
  396. },
  397. checkDeleteElements: function(item){
  398. if (this.deleteElements.length){
  399. if (!this.deleteElementsNode){
  400. this.deleteElementsNode = new Element("div", {"styles": this.css.deleteElementsNode}).inject(this.node);
  401. this.deleteElementsDeleteNode = new Element("div", {"styles": this.css.deleteElementsDeleteNode,"text": this.options.lp.deleteElements}).inject(this.deleteElementsNode);
  402. this.deleteElementsCancelNode = new Element("div", {"styles": this.css.deleteElementsCancelNode,"text": this.options.lp.deleteElementsCancel}).inject(this.deleteElementsNode);
  403. this.deleteElementsDeleteNode.addEvent("click", function(e){this.deleteSelectedElements(e);}.bind(this));
  404. this.deleteElementsCancelNode.addEvent("click", function(e){this.deleteSelectedElementsCancel(e);}.bind(this));
  405. }
  406. this.deleteElementsNode.position({
  407. relativeTo: (item) ? item.node : this.toolbarNode,
  408. position: "topRight",
  409. edge: "topLeft"
  410. });
  411. }else{
  412. if (this.deleteElementsNode){
  413. this.deleteElementsNode.destroy();
  414. this.deleteElementsNode = null;
  415. delete this.deleteElementsNode;
  416. }
  417. }
  418. },
  419. deleteSelectedElements: function(e){
  420. var _self = this;
  421. this.app.confirm("infor", e, this.options.lp.deleteElementsTitle, this.options.lp.deleteElementsConfirm, 300, 120, function(){
  422. var deleted = [];
  423. var doCount = 0;
  424. var readyCount = _self.deleteElements.length;
  425. var errorText = "";
  426. var complete;
  427. complete = function () {
  428. if (doCount === readyCount) {
  429. if (errorText) {
  430. _self.app.notice(errorText, "error", _self.propertyContentNode, {x: "left", y: "top"});
  431. }
  432. }
  433. };
  434. _self.deleteElements.each(function(element){
  435. element["delete"](function(){
  436. deleted.push(element);
  437. doCount++;
  438. if (_self.deleteElements.length===doCount){
  439. _self.deleteElements = _self.deleteElements.filter(function (item) {
  440. return !deleted.contains(item);
  441. });
  442. _self.checkDeleteElements();
  443. }
  444. complete();
  445. }, function(error){
  446. errorText = (errorText) ? errorText+"<br/><br/>"+error : error;
  447. doCount++;
  448. if (_self.deleteElements.length !== doCount) {
  449. } else {
  450. _self.deleteElements = _self.deleteElements.filter(function (item) {
  451. return !deleted.contains(item);
  452. });
  453. _self.checkDeleteElements();
  454. }
  455. complete();
  456. });
  457. });
  458. this.close();
  459. }, function(){
  460. this.close();
  461. });
  462. },
  463. deleteSelectedElementsCancel: function() {
  464. while (this.deleteElements.length){
  465. var element = this.deleteElements[0];
  466. element.setUndelete();
  467. //if (element.deleteNode) element.deleteNode.click();
  468. if (this.currentItem!==element){
  469. element.contentNode.setStyles(element.style.contentNode);
  470. if (element.data.id) element.actionNode.fade("out");
  471. }
  472. }
  473. this.checkDeleteElements();
  474. },
  475. destroy: function(){
  476. if (this.hidePingyinFun) this.app.content.removeEvent("mousedown", this.hidePingyinFun);
  477. if (this.resizePropertyContentNodeFun) this.app.removeEvent("resize", this.resizePropertyContentNodeFun);
  478. if (this.continueLoadFun) this.app.removeEvent("resize", this.continueLoadFun);
  479. if (this.removePingyinFun) this.app.removeEvent("queryClose", this.removePingyinFun);
  480. MWF.release(this);
  481. },
  482. _isActionManager: function(){
  483. return MWF.AC.isOrganizationManager();
  484. },
  485. _listElementNext: function(lastid, count, callback){
  486. this.actions.listPersonNext(lastid, count, function(json){
  487. if (callback) {
  488. callback.apply(this, [json]);
  489. }
  490. }.bind(this));
  491. },
  492. _newElement: function(data, explorer, i){
  493. return new MWF.xApplication.Org.PersonExplorer.Person(data, explorer, this.isEditor, i);
  494. },
  495. _listElementByKey: function(callback, failure, key){
  496. this.actions.listPersonByKey(function(json){
  497. if (callback) {
  498. callback.apply(this, [json]);
  499. }
  500. }.bind(this), failure, key);
  501. },
  502. _getAddElementData: function(){
  503. return {
  504. "employee": "",
  505. "password": "",
  506. "display": "",
  507. "qq": "",
  508. "mail": "",
  509. "weixin": "",
  510. "weibo": "",
  511. "mobile": "",
  512. "name": "",
  513. "controllerList": []
  514. };
  515. },
  516. getContentStyle: function(contentNode, node){
  517. var position = this.propertyContentNode.getPosition(this.propertyContentNode.getOffsetParent());
  518. var size = this.propertyContentNode.getSize();
  519. contentNode.position({"relativeTo": node,"position": "upperLeft","edge": "upperLeft"});
  520. return {
  521. "top": ""+position.y+"px",
  522. "left": ""+position.x+"px",
  523. "height": ""+size.y+"px",
  524. "width": ""+size.x+"px"
  525. };
  526. },
  527. openPerson: function(data, node){
  528. this.openContent("PersonExplorer", "PersonContent", data, node);
  529. },
  530. openGroup: function(data, node){
  531. this.openContent("GroupExplorer", "GroupContent", data, node);
  532. },
  533. openUnit: function(data, node){
  534. this.openContent("UnitExplorer", "UnitContent", data, node);
  535. },
  536. openRole: function(data, node){
  537. this.openContent("RoleExplorer", "RoleContent", data, node);
  538. },
  539. openContent: function(explorerClazz, contentClazz, data, node){
  540. MWF.xDesktop.requireApp("Org", explorerClazz, function(){
  541. var contentNode = new Element("div", {"styles": this.css.popContentNode}).inject(this.propertyContentNode, "top");
  542. var to = this.getContentStyle(contentNode, node);
  543. var resize = true;
  544. new Fx.Morph(contentNode, {
  545. "duration": 300,
  546. "transition": Fx.Transitions.Expo.easeOut
  547. }).start(to).chain(function(){
  548. content.setContentSize();
  549. resize = false;
  550. contentNode.setStyles({"position": "static","width": "100%","height": "100%"});
  551. }.bind(this));
  552. var item = {
  553. "explorer": this,
  554. "style": this.css.item,
  555. "data": data,
  556. "isEdit": false,
  557. "refresh": function(){},
  558. "propertyContentNode": contentNode
  559. };
  560. var content = new MWF.xApplication.Org[explorerClazz][contentClazz](item, true);
  561. var timeoutResize = function(){
  562. content.setContentSize();
  563. if (resize)window.setTimeout(function(){timeoutResize();}, 30);
  564. };
  565. window.setTimeout(function(){timeoutResize();}, 30);
  566. }.bind(this));
  567. }
  568. });
  569. MWF.xApplication.Org.$Explorer.Item = new Class({
  570. //Extends: MWF.xApplication.Organization.GroupExplorer.Group,
  571. initialize: function(data, explorer, isEditor, i){
  572. this.i = i;
  573. this.data = data;
  574. this.explorer = explorer;
  575. this.listNode = this.explorer.listNode;
  576. this.propertyContentNode = this.explorer.propertyContentNode;
  577. this.initStyle();
  578. this.selectedAttributes = [];
  579. this.isEdit = false;
  580. this.isEditor = isEditor;
  581. this.deleteSelected = false;
  582. },
  583. initStyle: function(){
  584. this.style = this.explorer.css.item;
  585. },
  586. refresh: function(){
  587. this.iconNode.getElement("img").set("src", this._getIcon());
  588. this._loadTextNode();
  589. if (this.content){
  590. if (this.content.titleInfor) this.content.titleInfor.refresh();
  591. if (this.content.bottomInfor) this.content.bottomInfor.refresh();
  592. }
  593. this.addActions();
  594. },
  595. load: function(){
  596. this.node = new Element("div", {"styles": this.style.node}).inject(this.listNode);
  597. // if (this.i<10){
  598. // var r = (59+((255-59)*this.i)/10).toInt();
  599. // var g = (118+((255-118)*this.i)/10).toInt();
  600. // var b = (182+((255-182)*this.i)/10).toInt();
  601. // this.node.setStyle("background-color", "rgb("+r+","+g+","+b+")");
  602. // }
  603. this.contentNode = new Element("div", {"styles": this.style.contentNode}).inject(this.node);
  604. this.iconNode = new Element("div", {"styles": this.style.iconNode}).inject(this.contentNode);
  605. var src = this._getIcon();
  606. var img = new Element("img", {
  607. "styles": this.style.iconImgNode,
  608. "src": src
  609. }).inject(this.iconNode);
  610. this.actionNode = new Element("div", {"styles": this.style.actionNode}).inject(this.contentNode);
  611. this.textNode = new Element("div", {"styles": this.style.textNode}).inject(this.contentNode);
  612. this._loadTextNode();
  613. this.setNewItem();
  614. this.node.inject(this.listNode);
  615. this.addActions();
  616. this.setEvent();
  617. },
  618. setNewItem: function(){
  619. if (!this.created){
  620. if (!this.data.id){
  621. this.created = false;
  622. this.contentNode.setStyles(this.style.contentNodeNew);
  623. }else {
  624. this.created = true;
  625. this.contentNode.setStyles(this.style.contentNode);
  626. }
  627. }
  628. },
  629. addActions: function(){
  630. if (this.isEditor){
  631. if (this.data.id){
  632. if (this.data.control.allowDelete){
  633. if (!this.deleteNode){
  634. this.deleteNode = new Element("div.o2icon-delete", {"styles": this.style.actionDeleteNode}).inject(this.actionNode);
  635. this.deleteNode.addEvent("click", function(e){
  636. if (!this.notDelete){
  637. if (!this.deleteSelected){
  638. this.setDelete();
  639. }else{
  640. this.setUndelete();
  641. }
  642. }
  643. e.stopPropagation();
  644. }.bind(this));
  645. if (this.explorer.currentItem===this){
  646. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  647. }
  648. }
  649. }
  650. }
  651. }
  652. },
  653. setDelete: function(){
  654. this.actionNode.fade("in");
  655. this.deleteNode.setStyles(this.style.actionDeleteNode_delete);
  656. this.deleteNode.removeClass("o2icon-delete").addClass("o2icon-off");
  657. this.contentNode.setStyles(this.style.contentNode_delete);
  658. this.contentNode.removeClass("mainColor_bg");
  659. this.textNode.setStyles(this.style.textNode);
  660. this.explorer.deleteElements.push(this);
  661. this.deleteSelected = true;
  662. this.contentNode.removeClass("mainColor_bg");
  663. this.contentNode.removeClass("mainColor_bg_opacity");
  664. this.explorer.checkDeleteElements(this);
  665. },
  666. setUndelete: function(){
  667. this.actionNode.fade("out");
  668. if (this.explorer.currentItem!==this){
  669. this.deleteNode.setStyles(this.style.actionDeleteNode);
  670. this.contentNode.setStyles(this.style.contentNode);
  671. this.contentNode.removeClass("mainColor_bg");
  672. this.textNode.setStyles(this.style.textNode);
  673. }else{
  674. this.contentNode.setStyles(this.style.contentNode_selected);
  675. this.contentNode.addClass("mainColor_bg");
  676. this.textNode.setStyles(this.style.textNode_selected);
  677. this.actionNode.setStyles(this.style.actionNode_selected);
  678. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  679. }
  680. this.deleteNode.removeClass("o2icon-off" ).addClass("o2icon-delete");
  681. this.explorer.deleteElements.erase(this);
  682. this.deleteSelected = false;
  683. this.explorer.checkDeleteElements(this);
  684. },
  685. setEvent: function(){
  686. this.contentNode.addEvents({
  687. "mouseover": function(e){
  688. if (this.explorer.currentItem!==this && !this.deleteSelected){
  689. this.contentNode.setStyles(this.style.nodeOver);
  690. this.contentNode.addClass("mainColor_bg_opacity");
  691. if (!this.deleteSelected) if (this.data.id) this.actionNode.fade("in");
  692. if (this.deleteNode)this.deleteNode.addClass("mainColor_color");
  693. if (this.addNode)this.addNode.addClass("mainColor_color");
  694. }
  695. }.bind(this),
  696. "mouseout": function(e){
  697. if (this.explorer.currentItem!==this && !this.deleteSelected){
  698. this.contentNode.setStyles(this.style.contentNode);
  699. this.contentNode.removeClass("mainColor_bg_opacity");
  700. if (!this.deleteSelected) if (this.data.id) this.actionNode.fade("out");
  701. // if (this.deleteNode)this.deleteNode.removeClass("mainColor_color");
  702. // if (this.addNode)this.addNode.removeClass("mainColor_color");
  703. }
  704. }.bind(this),
  705. "click": function(e){
  706. if (!this.deleteSelected){
  707. this.changeSelectedItem()
  708. }
  709. }.bind(this)
  710. });
  711. },
  712. changeSelectedItem: function (){
  713. if (this.explorer.currentItem){
  714. if (this.explorer.currentItem.unSelected()){
  715. this.selected();
  716. }else{
  717. this.explorer.app.notice(this.explorer.options.lp.elementSave, "error", this.propertyContentNode);
  718. }
  719. }else{
  720. this.selected();
  721. }
  722. },
  723. unSelected: function(){
  724. if (this.content.baseInfor.mode==="edit") return false;
  725. if (!this.deleteSelected){
  726. this.explorer.currentItem = null;
  727. this.contentNode.setStyles(this.style.contentNode);
  728. this.textNode.setStyles(this.style.textNode);
  729. this.actionNode.setStyles(this.style.actionNode);
  730. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode);
  731. this.contentNode.removeClass("mainColor_bg_opacity");
  732. this.contentNode.removeClass("mainColor_bg");
  733. if (this.deleteNode)this.deleteNode.removeClass("mainColor_color");
  734. if (this.addNode)this.addNode.removeClass("mainColor_color");
  735. }
  736. this.clearItemProperty();
  737. return true;
  738. },
  739. clearItemProperty: function(){
  740. this.explorer.propertyTitleNode.empty();
  741. if (this.content) this.content.destroy();
  742. this.explorer.propertyContentNode.empty();
  743. },
  744. selected: function(){
  745. debugger;
  746. this.explorer.currentItem = this;
  747. this.contentNode.setStyles(this.style.contentNode_selected);
  748. this.textNode.setStyles(this.style.textNode_selected);
  749. this.actionNode.setStyles(this.style.actionNode_selected);
  750. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  751. this.contentNode.removeClass("mainColor_bg_opacity");
  752. this.contentNode.addClass("mainColor_bg");
  753. if (this.deleteNode)this.deleteNode.removeClass("mainColor_color");
  754. if (this.addNode)this.addNode.removeClass("mainColor_color");
  755. this.showItemProperty();
  756. },
  757. editBaseInfor: function(){
  758. this.content.edit();
  759. },
  760. showItemProperty: function(){
  761. this.content = new MWF.xApplication.Org.PersonExplorer.PersonContent(this);
  762. },
  763. destroy: function(){
  764. if (this.explorer.currentItem===this){
  765. this.explorer.currentItem = null;
  766. this.clearItemProperty();
  767. }
  768. this.node.destroy();
  769. delete this;
  770. },
  771. "delete": function(success, failure){
  772. this.explorer.actions.deletePerson(this.data.id, function(){
  773. this.destroy();
  774. if (success) success();
  775. }.bind(this), function(xhr, text, error){
  776. var errorText = error;
  777. if (xhr) errorText = xhr.responseText;
  778. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  779. if (failure) failure();
  780. });
  781. },
  782. _loadTextNode: function(){
  783. this.textNode.set({"text": this.data.name});
  784. },
  785. _getIcon: function(nocache){
  786. var url = (this.data.id) ? this.explorer.actions.getPersonIcon(this.data.id) : "../x_component_Org/$Explorer/default/icon/man.png";
  787. return (nocache) ? url+"?"+(new Date().getTime()) : url;
  788. //return (this.data.id) ? this.explorer.actions.getPersonIcon(this.data.id) : "../x_component_Org/$Explorer/default/icon/man.png";
  789. // var src = "data:image/png;base64,"+this.data.icon;
  790. // if (!this.data.icon){
  791. // if (this.data.genderType==="f"){
  792. // src = "../x_component_Org/$Explorer/default/icon/female24.png"
  793. // }else{
  794. // src = "../x_component_Org/$Explorer/default/icon/man24.png"
  795. // }
  796. // }
  797. // return src;
  798. }
  799. });
  800. MWF.xApplication.Org.$Explorer.ItemContent = new Class({
  801. initialize: function (item, isClose) {
  802. this.item = item;
  803. this.isClose = isClose;
  804. this.explorer = this.item.explorer;
  805. this.contentNode = this.item.propertyContentNode;
  806. this.style = this.item.style.person;
  807. this.load();
  808. },
  809. _getData: function(callback){
  810. this.data = this.item.data;
  811. if (callback) callback();
  812. },
  813. load: function(){
  814. this.titleContentNode = new Element("div").inject(this.contentNode);
  815. this.propertyContentScrollNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.contentNode);
  816. this.propertyContentNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.propertyContentScrollNode);
  817. this.bottomContentNode = new Element("div").inject(this.contentNode);
  818. this._getData(function(){
  819. this.explorer.propertyTitleNode.set("text", this.data.name);
  820. this._showItemPropertyTitle();
  821. this.loadItemPropertyTab(function(){
  822. this._loadTabs();
  823. this._loadContent();
  824. if (this.propertyTab.pages.length) this.propertyTab.pages[0].showTabIm();
  825. }.bind(this));
  826. this._showItemPropertyBottom();
  827. this.setContentSizeFun = this.setContentSize.bind(this);
  828. this.setContentSize();
  829. this.explorer.app.addEvent("resize", this.setContentSizeFun);
  830. new MWF.widget.ScrollBar(this.propertyContentScrollNode, {
  831. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  832. });
  833. }.bind(this));
  834. //this.showItemPropertyTitle();
  835. },
  836. setContentSize: function(){
  837. var size = this.contentNode.getSize();
  838. var titleSize = this.titleContentNode.getSize();
  839. var bottomSize = this.bottomContentNode.getSize();
  840. var y = size.y-titleSize.y-bottomSize.y;
  841. this.propertyContentScrollNode.setStyle("height", ""+y+"px")
  842. },
  843. loadItemPropertyTab: function(callback){
  844. this.propertyTabContainerNode = new Element("div", {"styles": this.item.style.tabTitleNode}).inject(this.propertyContentNode, "top");
  845. MWF.require("MWF.widget.Tab", function(){
  846. this.propertyTab = new MWF.widget.Tab(this.propertyContentNode, {"style": "org", "useMainColor":true});
  847. this.propertyTab.load();
  848. this.propertyTab.tabNodeContainer.inject(this.propertyTabContainerNode);
  849. if (callback) callback();
  850. }.bind(this));
  851. },
  852. edit: function(){
  853. if (this.baseInfor) this.baseInfor.edit();
  854. },
  855. destroy: function(){
  856. if (this.setContentSizeFun) this.explorer.app.removeEvent("resize", this.setContentSizeFun);
  857. if (this.titleInfor) this.titleInfor.destroy();
  858. if (this.bottomInfor) this.bottomInfor.destroy();
  859. if (this.baseInfor) this.baseInfor.destroy();
  860. this.contentNode.empty();
  861. MWF.release(this);
  862. },
  863. _showItemPropertyTitle: function(){
  864. this.titleInfor = new MWF.xApplication.Org.$Explorer.ItemContent.TitleInfor(this);
  865. },
  866. _showItemPropertyBottom: function(){
  867. this.bottomInfor = new MWF.xApplication.Org.$Explorer.ItemContent.BottmInfor(this);
  868. },
  869. _loadTabs: function(){},
  870. _loadContent: function(){}
  871. });
  872. MWF.xApplication.Org.$Explorer.ItemContent.TitleInfor = new Class({
  873. initialize: function (content) {
  874. this.content = content;
  875. this.item = content.item;
  876. this.data = this.content.data;
  877. this.explorer = this.item.explorer;
  878. this.contentNode = this.content.titleContentNode;
  879. this.style = this._getStyle();
  880. this.load();
  881. },
  882. _getStyle: function(){
  883. return this.item.style.person;
  884. },
  885. load: function(){
  886. this.titleBgNode = new Element("div", {"styles": this.style.titleBgNode}).inject(this.contentNode);
  887. this.titleNode = new Element("div", {"styles": this.style.titleNode}).inject(this.titleBgNode);
  888. this.setBackground();
  889. this.titleInforNode = new Element("div#titleInfor", {"styles": this.style.titleInforNode}).inject(this.titleNode);
  890. this.titleInforLeftNode = new Element("div", {"styles": this.style.titleInforLeftNode}).inject(this.titleInforNode);
  891. this.titleInforRightNode = new Element("div", {"styles": this.style.titleInforRightNode}).inject(this.titleInforNode);
  892. this.loadLeftInfor();
  893. this.loadRightInfor();
  894. this.loadAction();
  895. if (this.content.isClose) this.createCloseNode();
  896. },
  897. createCloseNode: function(){
  898. this.closeNode = new Element("div", {"styles": this.style.titleCloseNode}).inject(this.titleBgNode);
  899. this.closeNode.addEvents({
  900. "mousedown": function(){this.closeNode.setStyles(this.style.titleCloseNode_down)}.bind(this),
  901. "mouseup": function(){this.closeNode.setStyles(this.style.titleCloseNode)}.bind(this),
  902. "click": function(){
  903. var node = this.content.contentNode;
  904. this.content.destroy();
  905. node.destroy();
  906. node = null;
  907. }.bind(this)
  908. });
  909. },
  910. setBackground: function(){
  911. this.titleBgNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/person_bg_bg.png)");
  912. this.titleNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/person_bg.png)");
  913. },
  914. loadLeftInfor: function(){
  915. if (!this.iconAreaNode) this.iconAreaNode = new Element("div", {"styles": this.style.titleInforIconAreaNode}).inject(this.titleInforLeftNode);
  916. if (!this.iconNode) this.iconNode = new Element("img", {"styles": this.style.titleInforIconNode}).inject(this.iconAreaNode);
  917. this.iconNode.set("src", this._getIcon());
  918. },
  919. _getIcon: function(nocache){
  920. var url = (this.data.id) ? this.explorer.actions.getPersonIcon(this.data.id) : "../x_component_Org/$Explorer/default/icon/man.png";
  921. return (nocache) ? url+"?"+(new Date().getTime()) : url;
  922. // var src = "data:image/png;base64,"+this.data.icon;
  923. // if (!this.data.icon){
  924. // if (this.data.genderType==="f"){
  925. // src = "../x_component_Org/$Explorer/default/icon/female.png"
  926. // }else{
  927. // src = "../x_component_Org/$Explorer/default/icon/man.png"
  928. // }
  929. // }
  930. // return src;
  931. },
  932. loadRightInfor: function(){
  933. var text = this.data.name+((this.data.employee) ? "("+this.data.employee+")" : "");
  934. if (!this.nameNode) this.nameNode = new Element("div", {"styles": this.style.titleInforNameNode}).inject(this.titleInforRightNode);
  935. if (!this.signatureNode) this.signatureNode = new Element("div", {"styles": this.style.titleInforSignatureNode}).inject(this.titleInforRightNode);
  936. this.nameNode.set("text", text);
  937. this.signatureNode.set("text", (this.data.signature || "" ));
  938. },
  939. refresh: function(){
  940. this.loadLeftInfor();
  941. this.loadRightInfor();
  942. },
  943. loadAction: function(){},
  944. destroy: function(){
  945. this.contentNode.empty();
  946. MWF.release(this);
  947. }
  948. });
  949. MWF.xApplication.Org.$Explorer.ItemContent.BottomInfor = new Class({
  950. initialize: function (content) {
  951. this.content = content;
  952. this.item = content.item;
  953. this.data = this.content.data;
  954. this.explorer = this.item.explorer;
  955. this.contentNode = this.content.bottomContentNode;
  956. this.style = this._getStyle();
  957. this.load();
  958. },
  959. _getStyle: function(){
  960. return this.item.style.person;
  961. },
  962. load: function(){
  963. this.readContentNode = new Element("div", {"styles": this.style.baseReadNode}).inject(this.contentNode);
  964. this.addInforList();
  965. },
  966. addInfor: function(text){
  967. return new Element("div", {"styles": this.style.baseReadContentNode, "text": text}).inject(this.readContentNode);
  968. },
  969. addInforList: function(){},
  970. refresh: function(){
  971. this.readContentNode.empty();
  972. this.addInforList();
  973. },
  974. destroy: function(){
  975. this.readContentNode.empty();
  976. this.readContentNode.destroy();
  977. MWF.release(this);
  978. }
  979. });