reload_popup.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.ReloadPopupMixin = Em.Mixin.create({
  20. reloadPopup: null,
  21. reloadSuccessCallback: function () {
  22. this.closeReloadPopup();
  23. },
  24. reloadErrorCallback: function (jqXHR, ajaxOptions, error, opt, params) {
  25. if (jqXHR.status) {
  26. this.closeReloadPopup();
  27. if (params.shouldUseDefaultHandler) {
  28. App.ajax.defaultErrorHandler(jqXHR, opt.url, opt.type, jqXHR.status);
  29. }
  30. } else {
  31. var timeout = Em.isNone(params.timeout) ? App.get('timeout') : params.timeout;
  32. this.showReloadPopup(params.reloadPopupText);
  33. if (params.callback) {
  34. var self = this;
  35. window.setTimeout(function () {
  36. params.callback.apply(self, params.args || []);
  37. }, timeout);
  38. }
  39. }
  40. },
  41. popupText: function(text) {
  42. return text || Em.I18n.t('app.reloadPopup.text');
  43. },
  44. showReloadPopup: function (text) {
  45. var self = this,
  46. bodyText = this.popupText(text);
  47. if (!this.get('reloadPopup')) {
  48. this.set('reloadPopup', App.ModalPopup.show({
  49. primary: null,
  50. secondary: null,
  51. showFooter: false,
  52. header: this.t('app.reloadPopup.header'),
  53. bodyClass: Ember.View.extend({
  54. template: Ember.Handlebars.compile("<div id='reload_popup' class='alert alert-info'>" +
  55. "{{view App.SpinnerView}}" +
  56. "<div><span>" + bodyText + "</span><a href='javascript:void(null)' onclick='location.reload();'>"
  57. + this.t('app.reloadPopup.link') + "</a></div>")
  58. }),
  59. onClose: function () {
  60. self.set('reloadPopup', null);
  61. this._super();
  62. }
  63. }));
  64. }
  65. },
  66. closeReloadPopup: function () {
  67. var reloadPopup = this.get('reloadPopup');
  68. if (reloadPopup) {
  69. reloadPopup.onClose();
  70. }
  71. }
  72. });