combobox.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. App.Combobox = Em.Select.extend({
  20. classNames:['combobox'],
  21. placeholderText:false,
  22. disabled:false,
  23. input:function () {
  24. return this.get('combobox').$element;
  25. }.property('combobox'),
  26. button:function () {
  27. return this.get('combobox').$button;
  28. }.property('combobox'),
  29. toggleDisabling:function () {
  30. var disabled = this.get('disabled') ? 'disabled' : false;
  31. this.get('input').attr('disabled', disabled);
  32. this.get('button').attr('disabled', disabled);
  33. }.observes('disabled'),
  34. content:function () {
  35. // convert DS.RecordsArray to array;
  36. var content = [
  37. {}
  38. ];
  39. var racks = this.get('recordArray');
  40. racks.forEach(function (cluster, index) {
  41. content.push(cluster);
  42. });
  43. return content;
  44. }.property('recordArray'),
  45. clearTextFieldValue:function () {
  46. var options = [];
  47. this.get('combobox').$element.val('');
  48. this.get('combobox').clearTarget();
  49. },
  50. test:function () {
  51. console.warn("qwerty");
  52. },
  53. didInsertElement:function () {
  54. this._super();
  55. this.set('combobox', this.$().combobox({
  56. template:'<div class="combobox-container"><input type="text" autocomplete="off" /><button class="add-on btn dropdown-toggle" data-dropdown="dropdown"><span class="caret"/><span class="combobox-clear"><i class="icon-remove"/></span></button></div>'
  57. }).data('combobox'));
  58. this.clearTextFieldValue(); // fix of script tags in
  59. if (this.get('placeholderText')) {
  60. this.get('combobox').$element.attr('placeholder', this.get('placeholderText'));
  61. }
  62. }
  63. });