modal_popup.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. '{{#if showFooter}}',
  34. '<div class="modal-footer">',
  35. '{{#if view.secondary}}<a class="btn" {{action onSecondary target="view"}}>{{view.secondary}}</a>{{/if}}',
  36. '{{#if view.primary}}<a class="btn btn-success" {{action onPrimary target="view"}}>{{view.primary}}</a>{{/if}}',
  37. '</div>',
  38. '{{/if}}',
  39. '</div>'
  40. ].join('\n')),
  41. header: '&nbsp;',
  42. body: '&nbsp;',
  43. encodeBody: true,
  44. // define bodyClass which extends Ember.View to use an arbitrary Handlebars template as the body
  45. primary: 'OK',
  46. secondary: 'Cancel',
  47. autoHeight: true,
  48. onPrimary: function() {
  49. },
  50. onSecondary: function() {
  51. this.hide();
  52. },
  53. onClose: function() {
  54. this.hide();
  55. },
  56. hide: function() {
  57. this.destroy();
  58. },
  59. showFooter: true,
  60. didInsertElement: function(){
  61. if(this.autoHeight){
  62. this._super();
  63. var block = this.$().find('#modal > .modal-body').first();
  64. block.css('max-height', $(window).height()- block.offset().top - 100); // fix popup height
  65. }
  66. }
  67. });
  68. App.ModalPopup.reopenClass({
  69. show: function(options) {
  70. var popup = this.create(options);
  71. popup.appendTo('#wrapper');
  72. }
  73. })
  74. App.showReloadPopup = function(){
  75. return App.ModalPopup.show({
  76. primary: null,
  77. secondary: null,
  78. showFooter: false,
  79. header: this.t('app.reloadPopup.header'),
  80. body: "<div class='alert alert-info'><div class='spinner'>" + this.t('app.reloadPopup.text') + "</div></div><div><a href='#' onclick='location.reload();'>" + this.t('app.reloadPopup.link') + "</a></div>",
  81. encodeBody: false
  82. });
  83. }