2 * Copyright (c) 2014 DataTorrent, Inc. ALL Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 .controller('CustomSettingsDemoCtrl', function($scope, $interval, $window, widgetDefinitions, defaultWidgets, RandomDataModel) {
23 // Add an additional widget with setting overrides
25 name: 'congfigurable widget',
26 directive: 'wt-scope-watch',
27 dataAttrName: 'value',
28 dataModelType: RandomDataModel,
32 settingsModalOptions: {
33 partialTemplateUrl: 'template/configurableWidgetModalOptions.html'
35 onSettingsClose: function (result, widget) {
36 if (widget.dataModel && widget.dataModel.updateLimit) {
37 widget.dataModel.updateLimit(result.dataModelOptions.limit);
41 name: 'override modal widget',
42 directive: 'wt-scope-watch',
43 dataAttrName: 'value',
44 dataModelType: RandomDataModel,
45 settingsModalOptions: {
46 templateUrl: 'template/WidgetSpecificSettings.html',
47 controller: 'WidgetSpecificSettingsCtrl',
50 onSettingsClose: function(result, widget) {
51 console.log('Widget-specific settings resolved!');
52 jQuery.extend(true, widget, result);
54 onSettingsDismiss: function(reason, scope) {
55 console.log('Settings have been dismissed: ', reason);
56 console.log('Dashboard scope: ', scope);
60 var defaultWidgets = [
61 { name: 'congfigurable widget' },
62 { name: 'override modal widget' }
65 $scope.dashboardOptions = {
67 widgetDefinitions: definitions,
68 defaultWidgets: defaultWidgets,
69 storage: $window.localStorage,
70 storageId: 'custom-settings',
73 // Overrides default $uibModal options.
74 // This can also be set on individual
75 // widget definition objects (see above).
76 settingsModalOptions: {
77 // This will completely override the modal template for all widgets.
78 // You also have the option to add to the default modal template with settingsModalOptions.partialTemplateUrl (see "configurable widget" above)
79 templateUrl: 'template/customSettingsTemplate.html'
80 // We could pass a custom controller name here to be used
81 // with the widget settings dialog, but for this demo we
82 // will just keep the default.
84 // controller: 'CustomSettingsModalCtrl'
86 // Other options passed to $uibModal.open can be put here,
92 // @see http://angular-ui.github.io/bootstrap/#/modal <-- heads up: routing on their site was broken as of this writing
96 // Called when a widget settings dialog is closed
97 // by the "ok" method (i.e., the promise is resolved
98 // and not rejected). This can also be set on individual
99 // widgets (see above).
100 onSettingsClose: function(result, widget, scope) {
101 console.log('Settings result: ', result);
102 console.log('Widget: ', widget);
103 console.log('Dashboard scope: ', scope);
104 jQuery.extend(true, widget, result);
107 // Called when a widget settings dialog is closed
108 // by the "cancel" method (i.e., the promise is rejected
109 // and not resolved). This can also be set on individual
110 // widgets (see above).
111 onSettingsDismiss: function(reason, scope) {
112 console.log('Settings have been dismissed: ', reason);
113 console.log('Dashboard scope: ', scope);
117 .controller('WidgetSpecificSettingsCtrl', function ($scope, $uibModalInstance, widget) {
118 // add widget to scope
119 $scope.widget = widget;
121 // set up result object
122 $scope.result = jQuery.extend(true, {}, widget);
124 $scope.ok = function () {
125 console.log('calling ok from widget-specific settings controller!');
126 $uibModalInstance.close($scope.result);
129 $scope.cancel = function () {
130 console.log('calling cancel from widget-specific settings controller!');
131 $uibModalInstance.dismiss('cancel');