modalPopup.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.ModalPopup = Ember.View.extend({
  20. template: Ember.Handlebars.compile([
  21. '<div class="modal-backdrop"></div><div class="modal" id="modal" tabindex="-1" role="dialog" aria-labelledby="modal-label" aria-hidden="true">',
  22. '<div class="modal-header">',
  23. '<a class="close" {{action onClose target="view"}}>x</a>',
  24. '<h3 id="modal-label">{{view.header}}</h3>',
  25. '</div>',
  26. '<div class="modal-body">',
  27. '{{#if bodyClass}}{{view bodyClass}}',
  28. '{{else}}{{body}}{{/if}}',
  29. '</div>',
  30. '<div class="modal-footer">',
  31. '{{#if view.secondary}}<a class="btn" {{action onSecondary target="view"}}>{{view.secondary}}</a>{{/if}}',
  32. '{{#if view.primary}}<a class="btn btn-success" {{action onPrimary target="view"}}>{{view.primary}}</a>{{/if}}',
  33. '</div>',
  34. '</div>'
  35. ].join('\n')),
  36. header: '&nbsp;',
  37. body: '&nbsp;',
  38. // define bodyClass which extends Ember.View to use an arbitrary Handlebars template as the body
  39. primary: 'OK',
  40. secondary: 'Cancel',
  41. onPrimary: function() {
  42. },
  43. onSecondary: function() {
  44. this.hide();
  45. },
  46. onClose: function() {
  47. this.hide();
  48. },
  49. hide: function() {
  50. this.destroy();
  51. }
  52. });
  53. App.ModalPopup.reopenClass({
  54. show: function(options) {
  55. var popup = this.create(options);
  56. popup.appendTo('#wrapper');
  57. }
  58. })