function controller($scope){
      var model = {};
      var structure = {};
      var widgetFilter = null;
      var structureName = {};
      var name = $scope.name;

      // Watching for changes on adfModel
      $scope.$watch('adfModel', function(oldVal, newVal) {
       // has model changed or is the model attribute not set
       if (newVal !== null || (oldVal === null && newVal === null)) {
         model = $scope.adfModel;
         widgetFilter = $scope.adfWidgetFilter;
         if ( ! model || ! model.rows ){
           structureName = $scope.structure;
           structure = dashboard.structures[structureName];
           if (structure){
             if (model){
               model.rows = angular.copy(structure).rows;
             } else {
               model = angular.copy(structure);
             }
             model.structure = structureName;
           } else {
             $log.error( 'could not find structure ' + structureName);
           }
         }

         if (model) {
           if (!model.title){
             model.title = 'Dashboard';
           }
           if (!model.titleTemplateUrl) {
             model.titleTemplateUrl = adfTemplatePath + 'dashboard-title.html';
           }
           $scope.model = model;
         } else {
           $log.error('could not find or create model');
         }
       }
      }, true);

      // edit mode
      $scope.editMode = false;
      $scope.editClass = '';

      //passs translate function from dashboard so we can translate labels inside html templates
      $scope.translate = dashboard.translate;

      function getNewModalScope() {
       var scope = $scope.$new();
       //pass translate function to the new scope so we can translate the labels inside the modal dialog
       scope.translate = dashboard.translate;
       return scope;
      }

      $scope.toggleEditMode = function(){
       $scope.editMode = ! $scope.editMode;
       if ($scope.editMode){
         if (!$scope.continuousEditMode) {
           $scope.modelCopy = angular.copy($scope.adfModel, {});
           $rootScope.$broadcast('adfIsEditMode');
         }
       }

       if (!$scope.editMode){
         $rootScope.$broadcast('adfDashboardChanged', name, model);
       }
      };

      $scope.$on('adfToggleEditMode', function() {
         $scope.toggleEditMode();
      });

      $scope.collapseAll = function(collapseExpandStatus){
       $rootScope.$broadcast('adfDashboardCollapseExpand',{collapseExpandStatus : collapseExpandStatus});
      };

      $scope.cancelEditMode = function(){
       $scope.editMode = false;
       if (!$scope.continuousEditMode) {
         $scope.modelCopy = angular.copy($scope.modelCopy, $scope.adfModel);
       }
       $rootScope.$broadcast('adfDashboardEditsCancelled');
      };

      // edit dashboard settings
      $scope.editDashboardDialog = function(){
       var editDashboardScope = getNewModalScope();
       // create a copy of the title, to avoid changing the title to
       // "dashboard" if the field is empty
       editDashboardScope.copy = {
         title: model.title
       };

       // pass dashboard structure to scope
       editDashboardScope.structures = dashboard.structures;

       // pass split function to scope, to be able to display structures in multiple columns
       editDashboardScope.split = adfUtilsService.split;

       var adfEditTemplatePath = adfTemplatePath + 'dashboard-edit.html';
       if(model.editTemplateUrl) {
         adfEditTemplatePath = model.editTemplateUrl;
       }
       var instance = $uibModal.open({
         scope: editDashboardScope,
         templateUrl: adfEditTemplatePath,
         backdrop: 'static',
         windowClass: 'adf-edit-dashboard-modal',
         size: 'lg'
       });
       editDashboardScope.changeStructure = function(name, structure){
         $log.info('change structure to ' + name);
         adfDashboardService.changeStructure(model, structure);
         if (model.structure !== name){
           model.structure = name;
         }
       };
       editDashboardScope.closeDialog = function(){
         // copy the new title back to the model
         model.title = editDashboardScope.copy.title;
         // close modal and destroy the scope
         instance.close();
         editDashboardScope.$destroy();
       };
      };

      // add widget dialog
      $scope.addWidgetDialog = function(){
       var addScope = getNewModalScope();
       var model = $scope.model;
       var widgets;
       if (angular.isFunction(widgetFilter)){
         widgets = {};
         angular.forEach(dashboard.widgets, function(widget, type){
           if (widgetFilter(widget, type, model)){
             widgets[type] = widget;
           }
         });
       } else {
         widgets = dashboard.widgets;
       }
       addScope.widgets = widgets;

       //pass translate function to the new scope so we can translate the labels inside the modal dialog
       addScope.translate = $scope.translate;

       // pass createCategories function to scope, if categories option is enabled
       if ($scope.options.categories){
         $scope.createCategories = adfDashboardService.createCategories;
       }

       var adfAddTemplatePath = adfTemplatePath + 'widget-add.html';
       if(model.addTemplateUrl) {
         adfAddTemplatePath = model.addTemplateUrl;
       }

       var opts = {
         scope: addScope,
         templateUrl: adfAddTemplatePath,
         windowClass: 'adf-add-widget-modal',
         backdrop: 'static'
       };

       var instance = $uibModal.open(opts);
       addScope.addWidget = function(widget){
         var w = {
           type: widget,
           config: adfDashboardService.createConfiguration(widget)
         };
         adfDashboardService.addNewWidgetToModel(model, w, name);
         // close and destroy
         instance.close();
         addScope.$destroy();

         // check for open edit mode immediately
         if (adfDashboardService.isEditModeImmediate(widget)){
           _openEditMode($scope, w);
         }
       };
       addScope.closeDialog = function(){
         // close and destroy
         instance.close();
         addScope.$destroy();
       };
      };

      $scope.addNewWidgetToModel = adfDashboardService.addNewWidgetToModel;
    }
Directive controller function.

@param dashboard scope