Combox.js 28 KB

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