From f2b987b96b76d985b20760096ef166a8f8011e8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 19 Feb 2014 21:50:47 +0100 Subject: [PATCH] major improvement to how modals are loaded, much more reuse in html dom elements, hopefully solves #109. --- src/app/directives/configModal.js | 44 ++++++++++++-------------- src/app/directives/kibanaPanel.js | 2 +- src/app/panels/annotations/editor.html | 9 +++--- src/app/panels/annotations/module.js | 8 ----- src/app/panels/graphite/editor.html | 2 +- src/app/partials/dashLoader.html | 2 +- src/app/partials/dashboard.html | 8 ++--- src/app/partials/paneleditor.html | 1 - 8 files changed, 31 insertions(+), 45 deletions(-) diff --git a/src/app/directives/configModal.js b/src/app/directives/configModal.js index ee71df41395..452b326d242 100644 --- a/src/app/directives/configModal.js +++ b/src/app/directives/configModal.js @@ -1,48 +1,44 @@ define([ 'angular', - 'underscore' + 'underscore', + 'jquery' ], -function (angular, _) { +function (angular, _, $) { 'use strict'; angular .module('kibana.directives') - .directive('configModal', function($modal,$q) { + .directive('configModal', function($modal, $q, $timeout) { return { restrict: 'A', link: function(scope, elem, attrs) { - var - model = attrs.kbnModel, - partial = attrs.configModal; + var partial = attrs.configModal; + var id = '#' + partial.replace('.html', '').replace(/[\/|\.|:]/g, '-') + '-' + scope.$id; - - // create a new modal. Can't reuse one modal unforunately as the directive will not - // re-render on show. - elem.bind('click',function(){ - - // Create a temp scope so we can discard changes to it if needed - var tmpScope = scope.$new(); - tmpScope[model] = angular.copy(scope[model]); - - tmpScope.editSave = function(panel) { - // Correctly set the top level properties of the panel object - _.each(panel,function(v,k) { - scope[model][k] = panel[k]; - }); - }; + elem.bind('click',function() { + if ($(id).length) { + elem.attr('data-target', id).attr('data-toggle', 'modal'); + return; + } var panelModal = $modal({ template: partial, persist: true, show: false, - scope: tmpScope, + scope: scope, keyboard: false }); - // and show it $q.when(panelModal).then(function(modalEl) { - modalEl.modal('show'); + elem.attr('data-target', id).attr('data-toggle', 'modal'); + + $timeout(function () { + if (!modalEl.data('modal').isShown) { + modalEl.modal('show'); + } + }, 50); }); + scope.$apply(); }); } diff --git a/src/app/directives/kibanaPanel.js b/src/app/directives/kibanaPanel.js index 2f3388cc256..1afc23ec00d 100644 --- a/src/app/directives/kibanaPanel.js +++ b/src/app/directives/kibanaPanel.js @@ -45,7 +45,7 @@ function (angular, $) { ''+ '' + + ' class="panel-text panel-title pointer" >' + '{{panel.title}}' + ''+ diff --git a/src/app/panels/annotations/editor.html b/src/app/panels/annotations/editor.html index a7c154e3bfe..ad6aa7a3eaa 100644 --- a/src/app/panels/annotations/editor.html +++ b/src/app/panels/annotations/editor.html @@ -4,20 +4,20 @@
+ - + -
Type Name
{{annotation.type}} {{annotation.name}}
@@ -32,7 +32,7 @@
- +
@@ -53,8 +53,7 @@ diff --git a/src/app/panels/annotations/module.js b/src/app/panels/annotations/module.js index 524434ad1bd..1ba1484ff5c 100644 --- a/src/app/panels/annotations/module.js +++ b/src/app/panels/annotations/module.js @@ -38,19 +38,11 @@ function (angular, app, _) { $scope.currentIsNew = true; }; - $scope.getAnnotationInfo = function(annotation) { - return annotation.target; - }; - $scope.edit = function(annotation) { $scope.currentAnnnotation = annotation; $scope.currentIsNew = false; }; - $scope.getInfo = function(annotation) { - return annotation.target; - }; - $scope.update = function() { $scope.currentAnnnotation = angular.copy(annotationDefaults); $scope.currentIsNew = true; diff --git a/src/app/panels/graphite/editor.html b/src/app/panels/graphite/editor.html index 8769ee14b71..32fb30fb41f 100644 --- a/src/app/panels/graphite/editor.html +++ b/src/app/panels/graphite/editor.html @@ -68,7 +68,7 @@ focus-me="segment.focus" ng-bind-html-unsafe="segment.html"> -