save_modal.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. required />
  30. <small class="gf-form-hint-text muted" ng-cloak>
  31. <span ng-class="{'text-error': ctrl.saveForm.message.$invalid && ctrl.saveForm.message.$dirty }">
  32. {{ctrl.message.length || 0}}
  33. </span>
  34. / {{ctrl.max}} characters
  35. </small>
  36. </label>
  37. </div>
  38. </div>
  39. <div class="gf-form-button-row text-center">
  40. <button type="submit" class="btn btn-success" ng-disabled="ctrl.saveForm.$invalid">Save</button>
  41. <button class="btn btn-inverse" ng-click="ctrl.dismiss();">Cancel</button>
  42. </div>
  43. </form>
  44. </div>
  45. `;
  46. export class SaveDashboardModalCtrl {
  47. message: string;
  48. max: number;
  49. saveForm: any;
  50. dismiss: () => void;
  51. /** @ngInject */
  52. constructor(private $scope, private dashboardSrv) {
  53. this.message = '';
  54. this.max = 64;
  55. }
  56. save() {
  57. if (!this.saveForm.$valid) {
  58. return;
  59. }
  60. var dashboard = this.dashboardSrv.getCurrent();
  61. var saveModel = dashboard.getSaveModelClone();
  62. var options = {message: this.message};
  63. return this.dashboardSrv.save(saveModel, options).then(this.dismiss);
  64. }
  65. }
  66. export function saveDashboardModalDirective() {
  67. return {
  68. restrict: 'E',
  69. template: template,
  70. controller: SaveDashboardModalCtrl,
  71. bindToController: true,
  72. controllerAs: 'ctrl',
  73. scope: {dismiss: "&"}
  74. };
  75. }
  76. coreModule.directive('saveDashboardModal', saveDashboardModalDirective);