save_modal.ts 2.3 KB

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