Combox.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. o2.widget = o2.widget || {};
  2. o2.require("o2.widget.Common", null, false);
  3. o2.widget.Combox = new Class({
  4. Implements: [Options, Events],
  5. Extends: o2.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 = o2.session.path+"/widget/$Combox/";
  20. this.cssPath = o2.session.path+"/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) o2.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 o2.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. var valueStr = this.input.node.get("value");
  181. this.input.node.set("value", "");
  182. if (valueStr){
  183. var values = valueStr.split(this.splitRegExp);
  184. if (this.options.count) values = values.slice(0, this.options.count);
  185. this.createItem(values, 0, data, function(){
  186. this.input.node.set("value", "");
  187. //this.input.hideOptionList();
  188. this.input.searchItems();
  189. this.input.setInputWidth();
  190. window.setTimeout(function(){
  191. // if (this.input){
  192. // this.input.node.blur();
  193. // this.input.node.focus();
  194. // }else{
  195. this.intoEdit();
  196. // }
  197. }.bind(this), 10);
  198. }.bind(this));
  199. //
  200. // values.each(function(value){
  201. // this.values.push(new o2.widget.Combox.Value(this, value, data));
  202. //
  203. // }.bind(this));
  204. //
  205. }
  206. },
  207. createItem: function(values, i, data, callback){
  208. if (values[i]){
  209. var value = values[i];
  210. var itemData = data;
  211. var itemText = value;
  212. if (!itemData){
  213. if (typeOf(value)==="object"){
  214. itemData = value.value;
  215. itemText = value.text;
  216. }
  217. }
  218. this.values.push(new o2.widget.Combox.Value(this, itemText, itemData, {
  219. "onLoad": function(){
  220. i++;
  221. if (values[i]){
  222. this.createItem(values, i, data, callback);
  223. }else{
  224. if (callback) callback();
  225. }
  226. }.bind(this)
  227. }));
  228. }
  229. },
  230. addNewValues: function(values, callback){
  231. this.createItem(values, 0, null, callback);
  232. },
  233. addNewValue: function(value, data){
  234. if (value){
  235. this.values.push(new o2.widget.Combox.Value(this, value, data));
  236. if (this.input){
  237. this.input.node.set("value", "");
  238. this.input.hideOptionList();
  239. this.input.searchItems();
  240. this.input.setInputWidth();
  241. }
  242. }
  243. },
  244. getFirst: function(){
  245. var node = this.node.getFirst();
  246. if (node){
  247. while (node && !node.retrieve("item")){ node = node.getNext(); }
  248. if (node) return node.retrieve("item");
  249. }
  250. return null;
  251. },
  252. getLast: function(){
  253. var node = this.node.getLast();
  254. if (node){
  255. while (node && !node.retrieve("item")){ node = node.getPrevious(); }
  256. if (node) return node.retrieve("item");
  257. }
  258. return null;
  259. },
  260. getNextItem: function(){
  261. var node = this.input.node.getNext();
  262. if (node) return node.retrieve("item");
  263. return null;
  264. },
  265. getPreviousItem: function(){
  266. var node = this.input.node.getPrevious();
  267. while (node && !node.retrieve("item")){ node = node.getPrevious(); }
  268. if (node) return node.retrieve("item");
  269. return null;
  270. },
  271. deleteItem: function(item){
  272. this.values.erase(item);
  273. item.node.destroy();
  274. item.input.destroy();
  275. o2.release(item);
  276. }
  277. });
  278. o2.widget.Combox.Value = new Class({
  279. Implements: [Options, Events],
  280. initialize: function(combox, value, data, options){
  281. this.setOptions(options);
  282. this.combox = combox;
  283. this.css = this.combox.css;
  284. this.value = value;
  285. this.data = data || null;
  286. this.type = "item";
  287. this.load();
  288. },
  289. getItemPosition: function(){
  290. var i=0;
  291. var item = this.getPreviousItem();
  292. while (item){
  293. i++;
  294. item = item.getPreviousItem();
  295. }
  296. return i;
  297. },
  298. checkData: function(callback){
  299. if (!this.data){
  300. this.combox.getSelectList(this.value, function(list){
  301. if (list.length==1){
  302. this.data = list[0].value;
  303. this.value = list[0].text;
  304. }
  305. if (callback) callback();
  306. }.bind(this));
  307. }else{
  308. if (callback) callback();
  309. }
  310. },
  311. load: function(){
  312. this.checkData(function(){
  313. this.node = new Element("div", {"styles": this.css.valueItemNode});
  314. if (this.combox.input){
  315. this.node.inject(this.combox.input.node, "before");
  316. }else{
  317. this.node.inject(this.combox.node);
  318. }
  319. if (this.getNextItem()){
  320. this.node.set("text", this.value+this.combox.options.splitShow);
  321. }else{
  322. this.node.set("text", this.value);
  323. }
  324. var prev = this.getPreviousItem();
  325. if (prev){
  326. prev.node.set("text", prev.value+this.combox.options.splitShow);
  327. }
  328. this.node.store("item", this);
  329. this.node.addEvents({
  330. "click": function(e){this.edit();e.stopPropagation();}.bind(this),
  331. "mouseover": function(e){this.node.setStyles(this.css.valueItemNode_over)}.bind(this),
  332. "mouseout": function(e){this.node.setStyles(this.css.valueItemNode)}.bind(this),
  333. "mousedown": function(e){e.stopPropagation();}.bind(this),
  334. //"mouseup": function(e){document.all.testCombox.innerHTML +="<br>"+this.value+"mouseup"; this.edit(); e.stopPropagation();}.bind(this),
  335. "focus": function(e){e.stopPropagation();}
  336. });
  337. if (this.options.noDataColor) if (!this.data) this.node.setStyle("color", "#bd0000");
  338. this.combox.fireEvent("commitInput", [this]);
  339. this.combox.fireEvent("change", [this]);
  340. this.fireEvent("load");
  341. }.bind(this));
  342. },
  343. edit: function(where){
  344. //this.combox.commitInput();
  345. if (!this.input){
  346. this.input = new o2.widget.Combox.Input(this.combox, this, this.value);
  347. this.input.node.inject(this.node, "after");
  348. this.input.hide();
  349. }
  350. this.input.node.show();
  351. this.input.setInputNodeStyles();
  352. this.node.hide();
  353. this.input.setInputPosition(where);
  354. this.combox.editItem = this;
  355. this.combox.input.hide();
  356. this.input.searchItems();
  357. },
  358. commitInput: function(data){
  359. var valueStr = this.input.node.get("value");
  360. if (valueStr){
  361. var values = valueStr.split(this.combox.splitRegExp);
  362. if (values.length>1){
  363. this.input.node.set("value", "");
  364. this.combox.editItem = null;
  365. var combox = this.combox;
  366. this.combox.deleteItem(this);
  367. //combox.intoEdit(this);
  368. combox.input.node.set("value", valueStr);
  369. combox.commitInput();
  370. }else{
  371. if (this.value==valueStr){
  372. this.data = data || this.data;
  373. }else{
  374. this.value = valueStr;
  375. this.data = data || null;
  376. }
  377. if (!this.data){
  378. if (this.options.noDataColor) this.node.setStyle("color", "#bd0000");
  379. }else{
  380. this.node.setStyle("color", "");
  381. }
  382. if (this.value){
  383. if (this.getNextItem()){
  384. this.node.set("text", this.value+this.combox.options.splitShow);
  385. }else{
  386. this.node.set("text", this.value);
  387. }
  388. this.node.show();
  389. this.input.hide();
  390. this.combox.editItem = null;
  391. this.combox.fireEvent("commitInput", [this]);
  392. this.combox.fireEvent("change", [this]);
  393. }else{
  394. this.combox.editItem = null;
  395. var combox = this.combox;
  396. this.input.hideOptionList();
  397. this.combox.deleteItem(this);
  398. combox.fireEvent("change", [this]);
  399. }
  400. }
  401. }else{
  402. this.combox.editItem = null;
  403. var combox = this.combox;
  404. this.input.hideOptionList();
  405. this.combox.deleteItem(this);
  406. combox.fireEvent("change", [this]);
  407. }
  408. window.setTimeout(function(){
  409. // if (this.combox.input){
  410. // this.combox.input.show();
  411. // this.combox.input.node.blur();
  412. // this.combox.input.node.focus();
  413. // }else{
  414. this.combox.intoEdit(this);
  415. // }
  416. }.bind(this), 10);
  417. },
  418. getNextItem: function(){
  419. var node = (this.input) ? this.input.node.getNext() : this.node.getNext();
  420. while (node && !node.retrieve("item")){ node = node.getNext(); }
  421. if (node) return node.retrieve("item");
  422. return null;
  423. },
  424. getPreviousItem: function(){
  425. var node = this.node.getPrevious();
  426. while (node && !node.retrieve("item")){ node = node.getPrevious(); }
  427. if (node) return node.retrieve("item");
  428. return null;
  429. }
  430. });
  431. o2.widget.Combox.Input = new Class({
  432. initialize: function(combox, bind, value){
  433. this.combox = combox;
  434. this.bind = bind;
  435. this.css = this.combox.css;
  436. this.node = new Element("input", {"styles": this.css.inputNode, "type":"text", "value": value});
  437. this.setInputNodeStyles();
  438. this.setInputWidth();
  439. this.setEvent();
  440. this.hideOption = false;
  441. },
  442. hide: function(){
  443. this.node.hide();
  444. this.hideOptionList();
  445. },
  446. setEvent: function(){
  447. this.node.addEvents({
  448. "mousedown": function(e){e.stopPropagation();},
  449. "input": function(e){
  450. this.setInputWidth();
  451. this.searchItems();
  452. var v = this.node.get("value");
  453. var s = v.substr(v.length-1, 1);
  454. if (s=="," || s==";"){
  455. this.node.set("value", v.substr(0, v.length-1));
  456. if (this.optionListNode && this.optionListNode.getChildren().length===1){
  457. this.confirmValue();
  458. }else{
  459. this.bind.commitInput();
  460. }
  461. }
  462. }.bind(this),
  463. "keydown": function(e){
  464. //if (e.code===186 || e.code===188 || e.code===13 || e.event.key==="," || e.event.key===";" || e.event.code==="Semicolon" || e.event.code==="Comma"){
  465. if (e.code===186 || e.code===188 || e.code===13){
  466. if (e.code===13){
  467. this.confirmValue();
  468. }else{
  469. if (this.optionListNode && this.optionListNode.getChildren().length===1){
  470. this.confirmValue();
  471. }else{
  472. this.bind.commitInput();
  473. }
  474. }
  475. e.preventDefault();
  476. e.stopPropagation();
  477. }
  478. if (e.code===37){ //left
  479. if (this.node.selectionStart==0 && this.node.selectionEnd==0){
  480. var item = this.bind.getPreviousItem();
  481. if (item){
  482. this.bind.commitInput();
  483. item.edit();
  484. }
  485. e.preventDefault();
  486. e.stopPropagation();
  487. }
  488. }
  489. if (e.code===39){ //right
  490. var idx = this.node.get("value").length;
  491. if (this.node.selectionStart==idx && this.node.selectionEnd==idx){
  492. var item = this.bind.getNextItem();
  493. if (item){
  494. this.bind.commitInput();
  495. item.edit("start");
  496. }
  497. e.preventDefault();
  498. e.stopPropagation();
  499. }
  500. }
  501. if (e.code===8){ //backspace
  502. if (this.node.selectionStart==0 && this.node.selectionEnd==0){
  503. var item = this.bind.getPreviousItem();
  504. if (item){
  505. this.bind.commitInput();
  506. item.edit();
  507. item.input.setInputPosition();
  508. }
  509. e.preventDefault();
  510. e.stopPropagation();
  511. }
  512. }
  513. if (e.code===46){ //del
  514. var idx = this.node.get("value").length;
  515. if (this.node.selectionStart==idx && this.node.selectionEnd==idx){
  516. var item = this.bind.getNextItem();
  517. if (item){
  518. this.bind.commitInput();
  519. item.edit();
  520. item.input.setInputPosition("start");
  521. }
  522. e.preventDefault();
  523. e.stopPropagation();
  524. }
  525. }
  526. if (e.code===38){ //up
  527. this.selectPrevOption();
  528. }
  529. if (e.code===40){ //down
  530. this.selectNextOption();
  531. }
  532. }.bind(this),
  533. "blur": function(e){
  534. //if (!this.noBlur){
  535. if ((this.combox.editItem == this.bind) || (!this.combox.editItem)){
  536. this.bind.commitInput();
  537. }
  538. e.stopPropagation();
  539. //}
  540. }.bind(this)
  541. });
  542. },
  543. setSelectedOption: function(node){
  544. var styles = node.getStyles("background-color", "background", "color");
  545. node.store("originalStyle", styles);
  546. node.setStyles(this.css.optionNode_selected);
  547. this.selectedOption = node;
  548. },
  549. selectPrevOption: function(){
  550. if (this.optionListNode){
  551. if (this.selectedOption) this.selectedOption.setStyles(this.selectedOption.retrieve("originalStyle"));
  552. node = (this.selectedOption)? (this.selectedOption.getPrevious() || this.optionListNode.getLast()) : this.optionListNode.getLast();
  553. if (node)this.setSelectedOption(node);
  554. this.optionListNode.scrollToNode(node, "top");
  555. }
  556. },
  557. selectNextOption: function(){
  558. if (this.optionListNode){
  559. if (this.selectedOption) this.selectedOption.setStyles(this.selectedOption.retrieve("originalStyle"));
  560. node = (this.selectedOption)? (this.selectedOption.getNext() || this.optionListNode.getFirst()) : this.optionListNode.getFirst();
  561. if (node)this.setSelectedOption(node);
  562. this.optionListNode.scrollToNode(node, "bottom");
  563. }
  564. },
  565. selectOption: function(node){
  566. if (this.optionListNode){
  567. if (this.selectedOption) this.selectedOption.setStyles(this.selectedOption.retrieve("originalStyle"));
  568. if (node)this.setSelectedOption(node);
  569. }
  570. },
  571. confirmValue: function(){
  572. if (this.optionListNode){
  573. if (this.selectedOption){
  574. var data = this.selectedOption.retrieve("data");
  575. var text = this.selectedOption.get("text");
  576. this.node.set("value", text);
  577. this.setInputWidth();
  578. this.bind.commitInput(data);
  579. this.selectedOption = null;
  580. }else{
  581. this.bind.commitInput();
  582. }
  583. }else{
  584. this.bind.commitInput();
  585. }
  586. },
  587. setInputWidth: function(){
  588. if (this.node){
  589. var value = this.node.get("value");
  590. if (!this.tmpDivNode) this.tmpDivNode = new Element("div").set("style", this.node.get("style")).setStyles({"display": "none", "float": "left", "width": "auto"}).inject(document.body);
  591. this.tmpDivNode.empty();
  592. value = value.replace(/\s/g, "&nbsp");
  593. this.tmpDivNode.set("html", value);
  594. var size = this.tmpDivNode.getComputedSize();
  595. var x = size.width-size.computedLeft-size.computedRight+5;
  596. var nodeSize = this.combox.node.getComputedSize();
  597. if (x<1) x=1;
  598. if (x>nodeSize.width) x = nodeSize.width;
  599. this.node.setStyle("width", ""+x+"px");
  600. this.node.focus();
  601. }
  602. },
  603. setInputPosition: function(where){
  604. this.node.focus();
  605. if (where==="start"){
  606. this.node.setSelectionRange(0,0);
  607. }else{
  608. var idx = this.node.get("value").length;
  609. this.node.setSelectionRange(idx,idx);
  610. }
  611. },
  612. setInputNodeStyles: function(){
  613. if (this.node){
  614. var styles = this.combox.node.getStyles("font-family", "min-height", "font-size", "font-weight", "font-variant", "font-style", "line-height", "color", "text-align");
  615. if (!this.inputHeight){
  616. var size = this.combox.node.getComputedSize();
  617. this.inputHeight = ""+size.height+"px";
  618. styles.height = ""+size.height+"px";
  619. }
  620. this.node.setStyles(styles);
  621. }
  622. },
  623. destroy: function(){
  624. this.node.destroy();
  625. o2.release(this);
  626. },
  627. searchItems: function(){
  628. this.hideOption = true;
  629. var value = this.node.get("value");
  630. if (value || this.combox.options.focusList){
  631. this.combox.getSelectList(value, function(list){
  632. if (this.hideOption){
  633. if (list.length){
  634. this.showOptionList(list);
  635. }else{
  636. this.hideOptionList();
  637. }
  638. }
  639. }.bind(this));
  640. //var list = this.combox.getSelectList(value);
  641. }else{
  642. this.hideOptionList();
  643. }
  644. },
  645. createOptionListNode: function(){
  646. this.optionListNode = new Element("div", {"styles": this.css.optionListNode});
  647. this.optionListNode.inject(this.node, "after");
  648. this.optionListNode.addEvents({
  649. "mousedown": function(e){
  650. this.noBlur = true;
  651. e.preventDefault();
  652. e.stopPropagation();
  653. }.bind(this),
  654. "mouseup": function(e){
  655. this.node.focus();
  656. this.noBlur = false;
  657. }.bind(this)
  658. });
  659. },
  660. showOptionList: function(list){
  661. if (!this.optionListNode) this.createOptionListNode();
  662. this.optionListNode.setStyle("dispaly", "block");
  663. this.optionListNode.empty();
  664. var _self = this;
  665. var styles = this.combox.node.getStyles("font-family", "font-size", "font-weight", "font-variant", "font-style", "line-height", "color", "text-align");
  666. list.each(function(option){
  667. var optionNode = new Element("div", {"styles": this.css.optionNode, "text": option.text}).inject(this.optionListNode);
  668. optionNode.store("data", option.value);
  669. optionNode.setStyles(styles);
  670. optionNode.addEvents({
  671. "mousedown": function(){
  672. // if (_self.bind.edit){
  673. // _self.bind.edit();
  674. // }else{
  675. // _self.bind.values[_self.bind.values.length-1].edit();
  676. // }
  677. _self.confirmValue();
  678. },
  679. "mouseover": function(){_self.selectOption(this);}
  680. });
  681. }.bind(this));
  682. var node = this.optionListNode.getFirst();
  683. if (node){
  684. var styles = node.getStyles("background-color", "background", "color");
  685. node.store("originalStyle", styles);
  686. node.setStyles(this.css.optionNode_selected);
  687. this.selectedOption = node;
  688. }
  689. this.optionListNode.position({
  690. "relativeTo": this.node,
  691. "position": "leftBottom",
  692. "edge": "leftTop",
  693. "offset": {"y": 3}
  694. });
  695. if (layout.desktop.offices){
  696. Object.each(layout.desktop.offices, function(office){
  697. if (this.optionListNode.isOverlap(office.officeNode)){
  698. office.hide();
  699. }
  700. }.bind(this));
  701. }
  702. },
  703. hideOptionList: function(){
  704. if (this.optionListNode){
  705. this.optionListNode.destroy();
  706. this.optionListNode = null;
  707. }
  708. this.hideOption = false;
  709. if (layout.desktop.offices){
  710. Object.each(layout.desktop.offices, function(office){
  711. if (layout.desktop.currentApp && layout.desktop.currentApp.appId===office.form.app.appId){
  712. var display = office.officeNode.retrieve("officeDisplay");
  713. if (display) office.officeNode.setStyle("display", display);
  714. }
  715. });
  716. }
  717. }
  718. });