modal_popup.js 2.2 KB

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