| 
									
										
										
										
											2015-12-04 19:21:33 +08:00
										 |  |  | define([ | 
					
						
							|  |  |  |   'angular', | 
					
						
							|  |  |  | ], | 
					
						
							|  |  |  | function (angular) { | 
					
						
							|  |  |  |   'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   var module = angular.module('grafana.directives'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   module.directive('pluginConfigLoader', function($compile) { | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       restrict: 'E', | 
					
						
							|  |  |  |       link: function(scope, elem) { | 
					
						
							|  |  |  |         var directive = 'grafana-plugin-core'; | 
					
						
							| 
									
										
										
										
											2015-12-05 00:34:48 +08:00
										 |  |  |         //wait for the parent scope to be applied.
 | 
					
						
							|  |  |  |         scope.$watch("current", function(newVal) { | 
					
						
							|  |  |  |           if (newVal) { | 
					
						
							|  |  |  |             if (newVal.module) { | 
					
						
							|  |  |  |               directive = 'grafana-plugin-'+newVal.type; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             scope.require([newVal.module], function () { | 
					
						
							|  |  |  |               var panelEl = angular.element(document.createElement(directive)); | 
					
						
							|  |  |  |               elem.append(panelEl); | 
					
						
							|  |  |  |               $compile(panelEl)(scope); | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2015-12-04 19:21:33 +08:00
										 |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   module.directive('grafanaPluginCore', function() { | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       restrict: 'E', | 
					
						
							|  |  |  |       templateUrl: 'app/features/org/partials/pluginConfigCore.html', | 
					
						
							|  |  |  |       transclude: true, | 
					
						
							| 
									
										
										
										
											2015-12-05 00:34:48 +08:00
										 |  |  |       link: function(scope) { | 
					
						
							| 
									
										
										
										
											2015-12-04 19:21:33 +08:00
										 |  |  |         scope.update = function() { | 
					
						
							|  |  |  |           //Perform custom save events to the plugins own backend if needed.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           // call parent update to commit the change to the plugin object.
 | 
					
						
							|  |  |  |           // this will cause the page to reload.
 | 
					
						
							|  |  |  |           scope._update(); | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |