$Explorer.js 41 KB

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