save_modal.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ///<reference path="../../headers/common.d.ts" />
  2. import coreModule from 'app/core/core_module';
  3. const template = `
  4. <div class="modal-body">
  5. <div class="modal-header">
  6. <h2 class="modal-header-title">
  7. <i class="fa fa-save"></i>
  8. <span class="p-l-1">Save changes</span>
  9. </h2>
  10. <a class="modal-header-close" ng-click="ctrl.dismiss();">
  11. <i class="fa fa-remove"></i>
  12. </a>
  13. </div>
  14. <form name="ctrl.saveForm" ng-submit="ctrl.save()" class="modal-content" novalidate>
  15. <h6 class="text-center">Add a note to describe your changes</h6>
  16. <div class="p-t-2">
  17. <div class="gf-form">
  18. <label class="gf-form-hint">
  19. <input
  20. type="text"
  21. name="message"
  22. class="gf-form-input"
  23. placeholder="Updates to &hellip;"
  24. give-focus="true"
  25. ng-model="ctrl.message"
  26. ng-model-options="{allowInvalid: true}"
  27. ng-maxlength="this.max"
  28. autocomplete="off" />
  29. <small class="gf-form-hint-text muted" ng-cloak>
  30. <span ng-class="{'text-error': ctrl.saveForm.message.$invalid && ctrl.saveForm.message.$dirty }">
  31. {{ctrl.message.length || 0}}
  32. </span>
  33. / {{ctrl.max}} characters
  34. </small>
  35. </label>
  36. </div>
  37. </div>
  38. <div class="gf-form-button-row text-center">
  39. <button type="submit" class="btn btn-success" ng-disabled="ctrl.saveForm.$invalid">Save</button>
  40. <button class="btn btn-inverse" ng-click="ctrl.dismiss();">Cancel</button>
  41. </div>
  42. </form>
  43. </div>
  44. `;
  45. export class SaveDashboardModalCtrl {
  46. message: string;
  47. max: number;
  48. saveForm: any;
  49. dismiss: () => void;
  50. /** @ngInject */
  51. constructor(private dashboardSrv) {
  52. this.message = '';
  53. this.max = 64;
  54. }
  55. save() {
  56. if (!this.saveForm.$valid) {
  57. return;
  58. }
  59. var dashboard = this.dashboardSrv.getCurrent();
  60. var saveModel = dashboard.getSaveModelClone();
  61. var options = {message: this.message};
  62. return this.dashboardSrv.save(saveModel, options).then(this.dismiss);
  63. }
  64. }
  65. export function saveDashboardModalDirective() {
  66. return {
  67. restrict: 'E',
  68. template: template,
  69. controller: SaveDashboardModalCtrl,
  70. bindToController: true,
  71. controllerAs: 'ctrl',
  72. scope: {dismiss: "&"}
  73. };
  74. }
  75. coreModule.directive('saveDashboardModal', saveDashboardModalDirective);