Combox.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. MWF.widget = MWF.widget || {};
  2. MWF.require("MWF.widget.Common", null, false);
  3. MWF.widget.Combox = new Class({
  4. Implements: [Options, Events],
  5. Extends: MWF.widget.Common,
  6. options: {
  7. "style": "default",
  8. "list": [],
  9. "optionsMethod": null,
  10. "splitStr": /,\s*|;\s*|,\s*|;\s*/g,
  11. "splitShow": ", ",
  12. "focusList": false,
  13. "noDataColor": true,
  14. "count": 0
  15. },
  16. initialize: function(options){
  17. this.setOptions(options);
  18. this.splitRegExp = new RegExp(this.options.splitStr);
  19. this.path = MWF.defaultPath+"/widget/$Combox/";
  20. this.cssPath = MWF.defaultPath+"/widget/$Combox/"+this.options.style+"/css.wcss";
  21. this._loadCss();
  22. this.values = [];
  23. //this.lastValue();
  24. this.load();
  25. },
  26. getSelectList: function(value, callback){
  27. var list = [];
  28. if (this.options.list.length){
  29. var listValues = this.options.list.filter(function(v, i){
  30. var key = (v.keyword || "")+v.text;
  31. return (key.indexOf(value)!==-1);
  32. });
  33. list = listValues;
  34. }
  35. if (this.options.optionsMethod){
  36. this.options.optionsMethod(value, function(methodValues){
  37. if (methodValues.length){
  38. if (list.length){
  39. list = list.concat(methodValues);
  40. }else{
  41. list = methodValues;
  42. }
  43. }
  44. if (callback) callback(list);
  45. }.bind(this));
  46. //var methodValues = this.options.optionsMethod(value);
  47. }else{
  48. if (callback) callback(list);
  49. }
  50. //return list;
  51. },
  52. load: function(){
  53. if (this.fireEvent("queryLoad")){
  54. this.node = new Element("div", {"styles": this.css.comboxNode});
  55. this.copyPrototype();
  56. this.setEvent();
  57. this.fireEvent("postLoad");
  58. }
  59. },
  60. clear: function(){
  61. if (this.input) MWF.release(this.input);
  62. this.input = null;
  63. this.node.empty();
  64. this.values = [];
  65. },
  66. getData: function(){
  67. var node = this.node.getFirst();
  68. var data = [];
  69. while (node){
  70. var item = node.retrieve("item");
  71. if (item){
  72. if (item.data || item.value){
  73. data.push(item.data || item.value);
  74. }
  75. }
  76. node = node.getNext();
  77. }
  78. return data;
  79. },
  80. copyPrototype: function(){
  81. this.inject = this.node.inject.bind(this.node);
  82. this.setStyle = this.node.setStyle.bind(this.node);
  83. this.setStyles = this.node.setStyles.bind(this.node);
  84. this.set = this.node.set.bind(this.node);
  85. // for (k in this.node.constructor.prototype){
  86. // if (typeOf(this.node[k])==="function"){
  87. // this[k] = this.node[k].bind(this.node);
  88. // }else{
  89. // this[k] = this.node[k];
  90. // }
  91. // }
  92. },
  93. setEvent:function(){
  94. this.node.addEvents({
  95. "focus": function(e){
  96. if (!this.selectStatus){
  97. if (!this.editItem) this.intoEdit(e);
  98. }
  99. }.bind(this),
  100. "mousedown": function(e){
  101. if (!this.selectStatus){
  102. if (!this.editItem) this.intoEdit(e);
  103. e.stopPropagation();
  104. e.preventDefault();
  105. }
  106. }.bind(this)
  107. // "selectstart": function(e){
  108. // if (e,event.buttons = "")
  109. // if (e.event.buttons!=0){
  110. // this.selectStatus = true;
  111. // this.stopEdit();
  112. // }
  113. // }.bind(this)
  114. // // "mouseup": function(e){
  115. // // this.selectStatus = false;
  116. // // }.bind(this),
  117. // "dblclick": function(e){
  118. // var range = document.createRange();
  119. // range.selectNodeContents(this.node);
  120. // alert(range.toString());
  121. // }.bind(this)
  122. });
  123. },
  124. stopEdit: function(){
  125. if (this.editItem){
  126. this.editItem.input.confirmValue();
  127. }else{
  128. if (this.input) this.input.confirmValue();
  129. }
  130. if (this.input) this.input.node.hide();
  131. },
  132. intoEdit: function(e){
  133. if (this.options.count){
  134. if (this.values.length>=this.options.count){
  135. // if (this.input) this.input.noBlur = true;
  136. if (this.input) this.input.node.hide();
  137. //this.getLast().edit();
  138. return false;
  139. }
  140. }
  141. if (!this.input){
  142. this.input = new MWF.widget.Combox.Input(this, this, "");
  143. this.input.node.inject(this.node);
  144. this.input.node.setStyle("width", "1px");
  145. }
  146. if (e){
  147. if (e.type==="item"){
  148. var node = e.node;
  149. if (e.input){
  150. node = e.input.optionListNode || e.input.node;
  151. }
  152. this.input.node.inject(node, "after");
  153. }else{
  154. var value = this.input.node.get("value");
  155. if (value) this.commitInput();
  156. var node = this.node.getFirst();
  157. while (node){
  158. if (node.retrieve("item")){
  159. var p = node.getPosition();
  160. var s = node.getSize();
  161. if (p.x>e.page.x && (p.y-3)<e.page.y && (p.y+s.y+3)>e.page.y) break;
  162. }
  163. node = node.getNext();
  164. }
  165. if (node){
  166. this.input.node.inject(node, "before");
  167. }else{
  168. this.input.node.inject(this.node);
  169. }
  170. }
  171. }
  172. this.input.node.show();
  173. this.input.setInputNodeStyles();
  174. //this.input.node.set("value", "111");
  175. this.input.node.focus();
  176. this.input.setInputPosition();
  177. if (this.options.focusList) this.input.searchItems();
  178. },
  179. commitInput: function(data){
  180. debugger;
  181. var valueStr = this.input.node.get("value");
  182. this.input.node.set("value", "");
  183. if (valueStr){
  184. var values = valueStr.split(this.splitRegExp);
  185. if (this.options.count) values = values.slice(0, this.options.count);
  186. this.createItem(values, 0, data, function(){
  187. this.input.node.set("value", "");
  188. //this.input.hideOptionList();
  189. this.input.searchItems();
  190. this.input.setInputWidth();
  191. window.setTimeout(function(){
  192. // if (this.input){
  193. // this.input.node.blur();
  194. // this.input.node.focus();
  195. // }else{
  196. this.intoEdit();
  197. // }
  198. }.bind(this), 10);
  199. }.bind(this));
  200. //
  201. // values.each(function(value){
  202. // this.values.push(new MWF.widget.Combox.Value(this, value, data));
  203. //
  204. // }.bind(this));
  205. //
  206. }
  207. },
  208. createItem: function(values, i, data, callback){
  209. if (values[i]){
  210. var value = values[i];
  211. var itemData = data;
  212. var itemText = value;
  213. if (!itemData){
  214. if (typeOf(value)==="object"){
  215. itemData = value.value;
  216. itemText = value.text;
  217. }
  218. }
  219. this.values.push(new MWF.widget.Combox.Value(this, itemText, itemData, {
  220. "onLoad": function(){
  221. i++;
  222. if (values[i]){
  223. this.createItem(values, i, data, callback);
  224. }else{
  225. if (callback) callback();
  226. }
  227. }.bind(this)
  228. }));
  229. }
  230. },
  231. addNewValues: function(values, callback){
  232. this.createItem(values, 0, null, callback);
  233. },
  234. addNewValue: function(value, data){
  235. debugger;
  236. if (value){
  237. this.values.push(new MWF.widget.Combox.Value(this, value, data));
  238. if (this.input){
  239. this.input.node.set("value", "");
  240. this.input.hideOptionList();
  241. this.input.searchItems();
  242. this.input.setInputWidth();
  243. }
  244. }
  245. },
  246. getFirst: function(){
  247. var node = this.node.getFirst();
  248. if (node){
  249. while (node && !node.retrieve("item")){ node = node.getNext(); }
  250. if (node) return node.retrieve("item");
  251. }
  252. return null;
  253. },
  254. getLast: function(){
  255. var node = this.node.getLast();
  256. if (node){
  257. while (node && !node.retrieve("item")){ node = node.getPrevious(); }
  258. if (node) return node.retrieve("item");
  259. }
  260. return null;
  261. },
  262. getNextItem: function(){
  263. var node = this.input.node.getNext();
  264. if (node) return node.retrieve("item");
  265. return null;
  266. },
  267. getPreviousItem: function(){
  268. var node = this.input.node.getPrevious();
  269. while (node && !node.retrieve("item")){ node = node.getPrevious(); }
  270. if (node) return node.retrieve("item");
  271. return null;
  272. },
  273. deleteItem: function(item){
  274. this.values.erase(item);
  275. item.node.destroy();
  276. item.input.destroy();
  277. MWF.release(item);
  278. }
  279. });
  280. MWF.widget.Combox.Value = new Class({
  281. Implements: [Options, Events],
  282. initialize: function(combox, value, data, options){
  283. this.setOptions(options);
  284. this.combox = combox;
  285. this.css = this.combox.css;
  286. this.value = value;
  287. this.data = data || null;
  288. this.type = "item";
  289. this.load();
  290. },
  291. getItemPosition: function(){
  292. var i=0;
  293. var item = this.getPreviousItem();
  294. while (item){
  295. i++;
  296. item = item.getPreviousItem();
  297. }
  298. return i;
  299. },
  300. checkData: function(callback){
  301. if (!this.data){
  302. this.combox.getSelectList(this.value, function(list){
  303. if (list.length==1){
  304. this.data = list[0].value;
  305. this.value = list[0].text;
  306. }
  307. if (callback) callback();
  308. }.bind(this));
  309. }else{
  310. if (callback) callback();
  311. }
  312. },
  313. load: function(){
  314. this.checkData(function(){
  315. this.node = new Element("div", {"styles": this.css.valueItemNode});
  316. if (this.combox.input){
  317. this.node.inject(this.combox.input.node, "before");
  318. }else{
  319. this.node.inject(this.combox.node);
  320. }
  321. if (this.getNextItem()){
  322. this.node.set("text", this.value+this.combox.options.splitShow);
  323. }else{
  324. this.node.set("text", this.value);
  325. }
  326. var prev = this.getPreviousItem();
  327. if (prev){
  328. prev.node.set("text", prev.value+this.combox.options.splitShow);
  329. }
  330. this.node.store("item", this);
  331. this.node.addEvents({
  332. "click": function(e){this.edit();e.stopPropagation();}.bind(this),
  333. "mouseover": function(e){this.node.setStyles(this.css.valueItemNode_over)}.bind(this),
  334. "mouseout": function(e){this.node.setStyles(this.css.valueItemNode)}.bind(this),
  335. "mousedown": function(e){e.stopPropagation();}.bind(this),
  336. //"mouseup": function(e){document.all.testCombox.innerHTML +="<br>"+this.value+"mouseup"; this.edit(); e.stopPropagation();}.bind(this),
  337. "focus": function(e){e.stopPropagation();}
  338. });
  339. if (this.options.noDataColor) if (!this.data) this.node.setStyle("color", "#bd0000");
  340. this.combox.fireEvent("commitInput", [this]);
  341. this.combox.fireEvent("change", [this]);
  342. this.fireEvent("load");
  343. }.bind(this));
  344. },
  345. edit: function(where){
  346. debugger;
  347. //this.combox.commitInput();
  348. if (!this.input){
  349. this.input = new MWF.widget.Combox.Input(this.combox, this, this.value);
  350. this.input.node.inject(this.node, "after");
  351. this.input.hide();
  352. }
  353. this.input.node.show();
  354. this.input.setInputNodeStyles();
  355. this.node.hide();
  356. this.input.setInputPosition(where);
  357. this.combox.editItem = this;
  358. this.combox.input.hide();
  359. this.input.searchItems();
  360. },
  361. commitInput: function(data){
  362. var valueStr = this.input.node.get("value");
  363. if (valueStr){
  364. var values = valueStr.split(this.combox.splitRegExp);
  365. if (values.length>1){
  366. this.input.node.set("value", "");
  367. this.combox.editItem = null;
  368. var combox = this.combox;
  369. this.combox.deleteItem(this);
  370. //combox.intoEdit(this);
  371. combox.input.node.set("value", valueStr);
  372. combox.commitInput();
  373. }else{
  374. if (this.value==valueStr){
  375. this.data = data || this.data;
  376. }else{
  377. this.value = valueStr;
  378. this.data = data || null;
  379. }
  380. if (!this.data){
  381. if (this.options.noDataColor) this.node.setStyle("color", "#bd0000");
  382. }else{
  383. this.node.setStyle("color", "");
  384. }
  385. if (this.value){
  386. if (this.getNextItem()){
  387. this.node.set("text", this.value+this.combox.options.splitShow);
  388. }else{
  389. this.node.set("text", this.value);
  390. }
  391. this.node.show();
  392. this.input.hide();
  393. this.combox.editItem = null;
  394. this.combox.fireEvent("commitInput", [this]);
  395. this.combox.fireEvent("change", [this]);
  396. }else{
  397. this.combox.editItem = null;
  398. var combox = this.combox;
  399. this.input.hideOptionList();
  400. this.combox.deleteItem(this);
  401. combox.fireEvent("change", [this]);
  402. }
  403. }
  404. }else{
  405. this.combox.editItem = null;
  406. var combox = this.combox;
  407. this.input.hideOptionList();
  408. this.combox.deleteItem(this);
  409. combox.fireEvent("change", [this]);
  410. }
  411. window.setTimeout(function(){
  412. // if (this.combox.input){
  413. // this.combox.input.show();
  414. // this.combox.input.node.blur();
  415. // this.combox.input.node.focus();
  416. // }else{
  417. this.combox.intoEdit(this);
  418. // }
  419. }.bind(this), 10);
  420. },
  421. getNextItem: function(){
  422. var node = (this.input) ? this.input.node.getNext() : this.node.getNext();
  423. while (node && !node.retrieve("item")){ node = node.getNext(); }
  424. if (node) return node.retrieve("item");
  425. return null;
  426. },
  427. getPreviousItem: function(){
  428. var node = this.node.getPrevious();
  429. while (node && !node.retrieve("item")){ node = node.getPrevious(); }
  430. if (node) return node.retrieve("item");
  431. return null;
  432. }
  433. });
  434. MWF.widget.Combox.Input = new Class({
  435. initialize: function(combox, bind, value){
  436. this.combox = combox;
  437. this.bind = bind;
  438. this.css = this.combox.css;
  439. this.node = new Element("input", {"styles": this.css.inputNode, "type":"text", "value": value});
  440. this.setInputNodeStyles();
  441. this.setInputWidth();
  442. this.setEvent();
  443. this.hideOption = false;
  444. },
  445. hide: function(){
  446. this.node.hide();
  447. this.hideOptionList();
  448. },
  449. setEvent: function(){
  450. this.node.addEvents({
  451. "mousedown": function(e){e.stopPropagation();},
  452. "input": function(e){
  453. this.setInputWidth();
  454. this.searchItems();
  455. var v = this.node.get("value");
  456. var s = v.substr(v.length-1, 1);
  457. if (s=="," || s==";"){
  458. debugger;
  459. this.node.set("value", v.substr(0, v.length-1));
  460. if (this.optionListNode && this.optionListNode.getChildren().length===1){
  461. this.confirmValue();
  462. }else{
  463. this.bind.commitInput();
  464. }
  465. }
  466. }.bind(this),
  467. "keydown": function(e){
  468. //if (e.code===186 || e.code===188 || e.code===13 || e.event.key==="," || e.event.key===";" || e.event.code==="Semicolon" || e.event.code==="Comma"){
  469. if (e.code===186 || e.code===188 || e.code===13){
  470. if (e.code===13){
  471. this.confirmValue();
  472. }else{
  473. if (this.optionListNode && this.optionListNode.getChildren().length===1){
  474. this.confirmValue();
  475. }else{
  476. this.bind.commitInput();
  477. }
  478. }
  479. e.preventDefault();
  480. e.stopPropagation();
  481. }
  482. if (e.code===37){ //left
  483. if (this.node.selectionStart==0 && this.node.selectionEnd==0){
  484. var item = this.bind.getPreviousItem();
  485. if (item){
  486. this.bind.commitInput();
  487. item.edit();
  488. }
  489. e.preventDefault();
  490. e.stopPropagation();
  491. }
  492. }
  493. if (e.code===39){ //right
  494. var idx = this.node.get("value").length;
  495. if (this.node.selectionStart==idx && this.node.selectionEnd==idx){
  496. var item = this.bind.getNextItem();
  497. if (item){
  498. this.bind.commitInput();
  499. item.edit("start");
  500. }
  501. e.preventDefault();
  502. e.stopPropagation();
  503. }
  504. }
  505. if (e.code===8){ //backspace
  506. if (this.node.selectionStart==0 && this.node.selectionEnd==0){
  507. var item = this.bind.getPreviousItem();
  508. if (item){
  509. this.bind.commitInput();
  510. item.edit();
  511. item.input.setInputPosition();
  512. }
  513. e.preventDefault();
  514. e.stopPropagation();
  515. }
  516. }
  517. if (e.code===46){ //del
  518. var idx = this.node.get("value").length;
  519. if (this.node.selectionStart==idx && this.node.selectionEnd==idx){
  520. var item = this.bind.getNextItem();
  521. if (item){
  522. this.bind.commitInput();
  523. item.edit();
  524. item.input.setInputPosition("start");
  525. }
  526. e.preventDefault();
  527. e.stopPropagation();
  528. }
  529. }
  530. if (e.code===38){ //up
  531. this.selectPrevOption();
  532. }
  533. if (e.code===40){ //down
  534. this.selectNextOption();
  535. }
  536. }.bind(this),
  537. "blur": function(e){
  538. //if (!this.noBlur){
  539. if ((this.combox.editItem == this.bind) || (!this.combox.editItem)){
  540. this.bind.commitInput();
  541. }
  542. e.stopPropagation();
  543. //}
  544. }.bind(this)
  545. });
  546. },
  547. setSelectedOption: function(node){
  548. var styles = node.getStyles("background-color", "background", "color");
  549. node.store("originalStyle", styles);
  550. node.setStyles(this.css.optionNode_selected);
  551. this.selectedOption = node;
  552. },
  553. selectPrevOption: function(){
  554. if (this.optionListNode){
  555. if (this.selectedOption) this.selectedOption.setStyles(this.selectedOption.retrieve("originalStyle"));
  556. node = (this.selectedOption)? (this.selectedOption.getPrevious() || this.optionListNode.getLast()) : this.optionListNode.getLast();
  557. if (node)this.setSelectedOption(node);
  558. this.optionListNode.scrollToNode(node, "top");
  559. }
  560. },
  561. selectNextOption: function(){
  562. if (this.optionListNode){
  563. if (this.selectedOption) this.selectedOption.setStyles(this.selectedOption.retrieve("originalStyle"));
  564. node = (this.selectedOption)? (this.selectedOption.getNext() || this.optionListNode.getFirst()) : this.optionListNode.getFirst();
  565. if (node)this.setSelectedOption(node);
  566. this.optionListNode.scrollToNode(node, "bottom");
  567. }
  568. },
  569. selectOption: function(node){
  570. if (this.optionListNode){
  571. if (this.selectedOption) this.selectedOption.setStyles(this.selectedOption.retrieve("originalStyle"));
  572. if (node)this.setSelectedOption(node);
  573. }
  574. },
  575. confirmValue: function(){
  576. if (this.optionListNode){
  577. if (this.selectedOption){
  578. var data = this.selectedOption.retrieve("data");
  579. var text = this.selectedOption.get("text");
  580. this.node.set("value", text);
  581. this.setInputWidth();
  582. this.bind.commitInput(data);
  583. this.selectedOption = null;
  584. }else{
  585. this.bind.commitInput();
  586. }
  587. }else{
  588. this.bind.commitInput();
  589. }
  590. },
  591. setInputWidth: function(){
  592. if (this.node){
  593. var value = this.node.get("value");
  594. if (!this.tmpDivNode) this.tmpDivNode = new Element("div").set("style", this.node.get("style")).setStyles({"display": "none", "float": "left", "width": "auto"}).inject(document.body);
  595. this.tmpDivNode.empty();
  596. value = value.replace(/\s/g, "&nbsp");
  597. this.tmpDivNode.set("html", value);
  598. var size = this.tmpDivNode.getComputedSize();
  599. var x = size.width-size.computedLeft-size.computedRight+5;
  600. var nodeSize = this.combox.node.getComputedSize();
  601. if (x<1) x=1;
  602. if (x>nodeSize.width) x = nodeSize.width;
  603. this.node.setStyle("width", ""+x+"px");
  604. this.node.focus();
  605. }
  606. },
  607. setInputPosition: function(where){
  608. this.node.focus();
  609. if (where==="start"){
  610. this.node.setSelectionRange(0,0);
  611. }else{
  612. var idx = this.node.get("value").length;
  613. this.node.setSelectionRange(idx,idx);
  614. }
  615. },
  616. setInputNodeStyles: function(){
  617. if (this.node){
  618. var styles = this.combox.node.getStyles("font-family", "min-height", "font-size", "font-weight", "font-variant", "font-style", "line-height", "color", "text-align");
  619. if (!this.inputHeight){
  620. var size = this.combox.node.getComputedSize();
  621. this.inputHeight = ""+size.height+"px";
  622. styles.height = ""+size.height+"px";
  623. }
  624. this.node.setStyles(styles);
  625. }
  626. },
  627. destroy: function(){
  628. this.node.destroy();
  629. MWF.release(this);
  630. },
  631. searchItems: function(){
  632. this.hideOption = true;
  633. var value = this.node.get("value");
  634. if (value || this.combox.options.focusList){
  635. this.combox.getSelectList(value, function(list){
  636. if (this.hideOption){
  637. if (list.length){
  638. this.showOptionList(list);
  639. }else{
  640. this.hideOptionList();
  641. }
  642. }
  643. }.bind(this));
  644. //var list = this.combox.getSelectList(value);
  645. }else{
  646. this.hideOptionList();
  647. }
  648. },
  649. createOptionListNode: function(){
  650. this.optionListNode = new Element("div", {"styles": this.css.optionListNode});
  651. this.optionListNode.inject(this.node, "after");
  652. this.optionListNode.addEvents({
  653. "mousedown": function(e){
  654. this.noBlur = true;
  655. e.preventDefault();
  656. e.stopPropagation();
  657. }.bind(this),
  658. "mouseup": function(e){
  659. this.node.focus();
  660. this.noBlur = false;
  661. }.bind(this)
  662. });
  663. },
  664. showOptionList: function(list){
  665. if (!this.optionListNode) this.createOptionListNode();
  666. this.optionListNode.setStyle("dispaly", "block");
  667. this.optionListNode.empty();
  668. var _self = this;
  669. var styles = this.combox.node.getStyles("font-family", "font-size", "font-weight", "font-variant", "font-style", "line-height", "color", "text-align");
  670. list.each(function(option){
  671. var optionNode = new Element("div", {"styles": this.css.optionNode, "text": option.text}).inject(this.optionListNode);
  672. optionNode.store("data", option.value);
  673. optionNode.setStyles(styles);
  674. optionNode.addEvents({
  675. "mousedown": function(){
  676. // if (_self.bind.edit){
  677. // _self.bind.edit();
  678. // }else{
  679. // _self.bind.values[_self.bind.values.length-1].edit();
  680. // }
  681. _self.confirmValue();
  682. },
  683. "mouseover": function(){_self.selectOption(this);}
  684. });
  685. }.bind(this));
  686. var node = this.optionListNode.getFirst();
  687. if (node){
  688. var styles = node.getStyles("background-color", "background", "color");
  689. node.store("originalStyle", styles);
  690. node.setStyles(this.css.optionNode_selected);
  691. this.selectedOption = node;
  692. }
  693. this.optionListNode.position({
  694. "relativeTo": this.node,
  695. "position": "leftBottom",
  696. "edge": "leftTop",
  697. "offset": {"y": 3}
  698. });
  699. if (layout.desktop.offices){
  700. Object.each(layout.desktop.offices, function(office){
  701. if (this.optionListNode.isOverlap(office.officeNode)){
  702. office.hide();
  703. }
  704. }.bind(this));
  705. }
  706. },
  707. hideOptionList: function(){
  708. if (this.optionListNode){
  709. this.optionListNode.destroy();
  710. this.optionListNode = null;
  711. }
  712. this.hideOption = false;
  713. if (layout.desktop.offices){
  714. Object.each(layout.desktop.offices, function(office){
  715. if (layout.desktop.currentApp && layout.desktop.currentApp.appId===office.form.app.appId){
  716. var display = office.officeNode.retrieve("officeDisplay");
  717. if (display) office.officeNode.setStyle("display", display);
  718. }
  719. });
  720. }
  721. }
  722. });