2525
2626
2727
28- angular . module ( 'adf' , [ 'adf.provider' , 'ui.bootstrap' ] )
28+ angular . module ( 'adf' , [ 'adf.provider' , 'adf.locale' , ' ui.bootstrap'] )
2929 . value ( 'adfTemplatePath' , '../src/templates/' )
3030 . value ( 'rowTemplate' , '<adf-dashboard-row row="row" adf-model="adfModel" options="options" edit-mode="editMode" ng-repeat="row in column.rows" />' )
3131 . value ( 'columnTemplate' , '<adf-dashboard-column column="column" adf-model="adfModel" options="options" edit-mode="editMode" ng-repeat="column in row.columns" />' )
3232 . value ( 'adfVersion' , '0.12.0-SNAPSHOT' ) ;
3333
34+ /*
35+ * The MIT License
36+ *
37+ * Copyright (c) 2015, Sebastian Sdorra
38+ *
39+ * Permission is hereby granted, free of charge, to any person obtaining a copy
40+ * of this software and associated documentation files (the "Software"), to deal
41+ * in the Software without restriction, including without limitation the rights
42+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43+ * copies of the Software, and to permit persons to whom the Software is
44+ * furnished to do so, subject to the following conditions:
45+ *
46+ * The above copyright notice and this permission notice shall be included in
47+ * all copies or substantial portions of the Software.
48+ *
49+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55+ * SOFTWARE.
56+ */
57+
58+
59+
60+ angular . module ( 'adf.locale' , [ ] )
61+
3462/*
3563* The MIT License
3664*
@@ -556,6 +584,16 @@ angular.module('adf')
556584 $scope . editMode = false ;
557585 $scope . editClass = '' ;
558586
587+ //passs translate function from dashboard so we can translate labels inside html templates
588+ $scope . translate = dashboard . translate ;
589+
590+ function getNewModalScope ( ) {
591+ var scope = $scope . $new ( ) ;
592+ //pass translate function to the new scope so we can translate the labels inside the modal dialog
593+ scope . translate = dashboard . translate ;
594+ return scope ;
595+ }
596+
559597 $scope . toggleEditMode = function ( ) {
560598 $scope . editMode = ! $scope . editMode ;
561599 if ( $scope . editMode ) {
@@ -588,7 +626,7 @@ angular.module('adf')
588626
589627 // edit dashboard settings
590628 $scope . editDashboardDialog = function ( ) {
591- var editDashboardScope = $scope . $new ( ) ;
629+ var editDashboardScope = getNewModalScope ( ) ;
592630 // create a copy of the title, to avoid changing the title to
593631 // "dashboard" if the field is empty
594632 editDashboardScope . copy = {
@@ -629,7 +667,7 @@ angular.module('adf')
629667
630668 // add widget dialog
631669 $scope . addWidgetDialog = function ( ) {
632- var addScope = $scope . $new ( ) ;
670+ var addScope = getNewModalScope ( ) ;
633671 var model = $scope . model ;
634672 var widgets ;
635673 if ( angular . isFunction ( widgetFilter ) ) {
@@ -644,6 +682,9 @@ angular.module('adf')
644682 }
645683 addScope . widgets = widgets ;
646684
685+ //pass translate function to the new scope so we can translate the labels inside the modal dialog
686+ addScope . translate = $scope . translate ;
687+
647688 // pass createCategories function to scope, if categories option is enabled
648689 if ( $scope . options . categories ) {
649690 $scope . createCategories = createCategories ;
@@ -690,7 +731,7 @@ angular.module('adf')
690731 var options = {
691732 name : $attr . name ,
692733 editable : true ,
693- enableConfirmDelete : stringToBoolean ( $attr . enableconfirmdelete ) ,
734+ enableConfirmDelete : stringToBoolean ( $attr . enableConfirmDelete ) ,
694735 maximizable : stringToBoolean ( $attr . maximizable ) ,
695736 collapsible : stringToBoolean ( $attr . collapsible ) ,
696737 categories : stringToBoolean ( $attr . categories )
@@ -729,6 +770,92 @@ angular.module('adf')
729770*/
730771
731772
773+
774+ /**
775+ * @ngdoc object
776+ * @name adf.locale#adfLocale
777+ * @description
778+ *
779+ * Holds settings and values for framework supported locales
780+ */
781+ angular . module ( 'adf.locale' )
782+ . constant ( 'adfLocale' ,
783+ {
784+ defaultLocale : 'en-GB' ,
785+ frameworkLocales : {
786+ 'en-GB' : {
787+ ADF_COMMON_CLOSE : 'Close' ,
788+ ADF_COMMON_DELETE : 'Delete' ,
789+ ADF_COMMON_TITLE : 'Title' ,
790+ ADF_COMMON_CANCEL : 'Cancel' ,
791+ ADF_COMMON_APPLY : 'Apply' ,
792+ ADF_COMMON_EDIT_DASHBOARD : 'Edit dashboard' ,
793+ ADF_EDIT_DASHBOARD_STRUCTURE_LABEL : 'Structure' ,
794+ ADF_DASHBOARD_TITLE_TOOLTIP_ADD : 'Add new widget' ,
795+ ADF_DASHBOARD_TITLE_TOOLTIP_SAVE : 'Save changes' ,
796+ ADF_DASHBOARD_TITLE_TOOLTIP_EDIT_MODE : 'Enable edit mode' ,
797+ ADF_DASHBOARD_TITLE_TOOLTIP_UNDO : 'Undo changes' ,
798+ ADF_WIDGET_ADD_HEADER : 'Add new widget' ,
799+ ADF_WIDGET_DELETE_CONFIRM_MESSAGE : 'Are you sure you want to delete this widget ?' ,
800+ ADF_WIDGET_TOOLTIP_REFRESH : 'Reload widget Content' ,
801+ ADF_WIDGET_TOOLTIP_MOVE : 'Change widget location' ,
802+ ADF_WIDGET_TOOLTIP_COLLAPSE : 'Collapse widget' ,
803+ ADF_WIDGET_TOOLTIP_EXPAND : 'Expand widget' ,
804+ ADF_WIDGET_TOOLTIP_EDIT : 'Edit widget configuration' ,
805+ ADF_WIDGET_TOOLTIP_FULLSCREEN : 'Fullscreen widget' ,
806+ ADF_WIDGET_TOOLTIP_REMOVE : 'Remove widget'
807+ } ,
808+ 'sv-SE' : {
809+ ADF_COMMON_CLOSE : 'Stäng' ,
810+ ADF_COMMON_DELETE : 'Ta bort' ,
811+ ADF_COMMON_TITLE : 'Titel' ,
812+ ADF_COMMON_CANCEL : 'Avbryt' ,
813+ ADF_COMMON_APPLY : 'Använd' ,
814+ ADF_COMMON_EDIT_DASHBOARD : 'Redigera dashboard' ,
815+ ADF_EDIT_DASHBOARD_STRUCTURE_LABEL : 'Struktur' ,
816+ ADF_DASHBOARD_TITLE_TOOLTIP_ADD : 'Lägg till ny widget' ,
817+ ADF_DASHBOARD_TITLE_TOOLTIP_SAVE : 'Spara förändringar' ,
818+ ADF_DASHBOARD_TITLE_TOOLTIP_EDIT_MODE : 'Slå på redigeringsläge' ,
819+ ADF_DASHBOARD_TITLE_TOOLTIP_UNDO : 'Ångra förändringar' ,
820+ ADF_WIDGET_ADD_HEADER : 'Lägg till ny widget' ,
821+ ADF_WIDGET_DELETE_CONFIRM_MESSAGE : 'Är du säker på att du vill ta bort denna widget ?' ,
822+ ADF_WIDGET_TOOLTIP_REFRESH : 'Ladda om widget' ,
823+ ADF_WIDGET_TOOLTIP_MOVE : 'Ändra widgets position' ,
824+ ADF_WIDGET_TOOLTIP_COLLAPSE : 'Stäng widget' ,
825+ ADF_WIDGET_TOOLTIP_EXPAND : 'Öppna widget' ,
826+ ADF_WIDGET_TOOLTIP_EDIT : 'Ändra widget konfigurering' ,
827+ ADF_WIDGET_TOOLTIP_FULLSCREEN : 'Visa widget i fullskärm' ,
828+ ADF_WIDGET_TOOLTIP_REMOVE : 'Ta bort widget'
829+ }
830+ }
831+ }
832+ ) ;
833+
834+ /*
835+ * The MIT License
836+ *
837+ * Copyright (c) 2015, Sebastian Sdorra
838+ *
839+ * Permission is hereby granted, free of charge, to any person obtaining a copy
840+ * of this software and associated documentation files (the "Software"), to deal
841+ * in the Software without restriction, including without limitation the rights
842+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
843+ * copies of the Software, and to permit persons to whom the Software is
844+ * furnished to do so, subject to the following conditions:
845+ *
846+ * The above copyright notice and this permission notice shall be included in
847+ * all copies or substantial portions of the Software.
848+ *
849+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
850+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
851+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
852+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
853+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
854+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
855+ * SOFTWARE.
856+ */
857+
858+
732859/* global angular */
733860angular . module ( 'adf' )
734861 . filter ( 'adfOrderByObjectKey' , [ "$filter" , function ( $filter ) {
@@ -777,8 +904,8 @@ angular.module('adf')
777904 *
778905 * The dashboardProvider can be used to register structures and widgets.
779906 */
780- angular . module ( 'adf.provider' , [ ] )
781- . provider ( 'dashboard' , function ( ) {
907+ angular . module ( 'adf.provider' , [ 'adf.locale' ] )
908+ . provider ( 'dashboard' , [ "adfLocale" , function ( adfLocale ) {
782909
783910 var widgets = { } ;
784911 var widgetsPath = '' ;
@@ -790,12 +917,29 @@ angular.module('adf.provider', [])
790917 <span class="sr-only">loading ...</span>\n\
791918 </div>\n\
792919 </div>' ;
920+ var customWidgetTemplatePath = null ;
793921
794922 // default apply function of widget.edit.apply
795923 var defaultApplyFunction = function ( ) {
796924 return true ;
797925 } ;
798926
927+ var activeLocale = adfLocale . defaultLocale ;
928+ var locales = adfLocale . frameworkLocales ;
929+
930+ function getLocales ( ) {
931+ return locales ;
932+ }
933+
934+ function getActiveLocale ( ) {
935+ return activeLocale ;
936+ }
937+
938+ function translate ( label ) {
939+ var translation = locales [ activeLocale ] [ label ] ;
940+ return translation ? translation : label ;
941+ }
942+
799943 /**
800944 * @ngdoc method
801945 * @name adf.dashboardProvider#widget
@@ -955,6 +1099,70 @@ angular.module('adf.provider', [])
9551099 return this ;
9561100 } ;
9571101
1102+ /**
1103+ * @ngdoc method
1104+ * @name adf.dashboardProvider#customWidgetTemplatePath
1105+ * @propertyOf adf.dashboardProvider
1106+ * @description
1107+ *
1108+ * Changes the container template for the widgets
1109+ *
1110+ * @param {string } path to the custom widget template
1111+ *
1112+ * @returns {Object } self
1113+ */
1114+ this . customWidgetTemplatePath = function ( templatePath ) {
1115+ customWidgetTemplatePath = templatePath ;
1116+ return this ;
1117+ } ;
1118+
1119+ /**
1120+ * @ngdoc method
1121+ * @name adf.dashboardProvider#setLocale
1122+ * @methodOf adf.dashboardProvider
1123+ * @description
1124+ *
1125+ * Changes the locale setting of adf
1126+ *
1127+ * @param {string } ISO Language Code
1128+ *
1129+ * @returns {Object } self
1130+ */
1131+ this . setLocale = function ( locale ) {
1132+ if ( locales [ locale ] ) {
1133+ activeLocale = locale ;
1134+ } else {
1135+ throw new Error ( 'Cannot set locale: ' + locale + '. Locale is not defined.' ) ;
1136+ }
1137+ return this ;
1138+ } ;
1139+
1140+ /**
1141+ * @ngdoc method
1142+ * @name adf.dashboardProvider#addLocale
1143+ * @methodOf adf.dashboardProvider
1144+ * @description
1145+ *
1146+ * Adds a new locale to adf
1147+ *
1148+ * @param {string } ISO Language Code for the new locale
1149+ * @param {object } translations for the locale.
1150+ *
1151+ * @returns {Object } self
1152+ */
1153+ this . addLocale = function ( locale , translations ) {
1154+ if ( ! angular . isString ( locale ) ) {
1155+ throw new Error ( 'locale must be an string' ) ;
1156+ }
1157+
1158+ if ( ! angular . isObject ( translations ) ) {
1159+ throw new Error ( 'translations must be an object' ) ;
1160+ }
1161+
1162+ locales [ locale ] = translations ;
1163+ return this ;
1164+ } ;
1165+
9581166 /**
9591167 * @ngdoc service
9601168 * @name adf.dashboard
@@ -967,6 +1175,10 @@ angular.module('adf.provider', [])
9671175 * @property {Array.<Object> } structures Array of registered structures.
9681176 * @property {string } messageTemplate Template for messages.
9691177 * @property {string } loadingTemplate Template for widget loading.
1178+ * @property {method } sets locale of adf.
1179+ * @property {Array.<Object> } hold all of the locale translations.
1180+ * @property {string } the active locale setting.
1181+ * @property {method } translation function passed to templates.
9701182 *
9711183 * @returns {Object } self
9721184 */
@@ -979,6 +1191,11 @@ angular.module('adf.provider', [])
9791191 structures : structures ,
9801192 messageTemplate : messageTemplate ,
9811193 loadingTemplate : loadingTemplate ,
1194+ customWidgetTemplatePath : customWidgetTemplatePath ,
1195+ setLocale : this . setLocale ,
1196+ locales : getLocales ,
1197+ activeLocale : getActiveLocale ,
1198+ translate : translate ,
9821199
9831200 /**
9841201 * @ngdoc method
@@ -1011,7 +1228,7 @@ angular.module('adf.provider', [])
10111228 } ;
10121229 } ;
10131230
1014- } ) ;
1231+ } ] ) ;
10151232
10161233/*
10171234* The MIT License
@@ -1364,6 +1581,10 @@ angular.module('adf')
13641581
13651582 function preLink ( $scope ) {
13661583 var definition = $scope . definition ;
1584+
1585+ //passs translate function from dashboard so we can translate labels inside html templates
1586+ $scope . translate = dashboard . translate ;
1587+
13671588 if ( definition ) {
13681589 var w = dashboard . widgets [ definition . type ] ;
13691590 if ( w ) {
@@ -1449,6 +1670,8 @@ angular.module('adf')
14491670 $scope . remove = function ( ) {
14501671 if ( $scope . options . enableConfirmDelete ) {
14511672 var deleteScope = $scope . $new ( ) ;
1673+ deleteScope . translate = dashboard . translate ;
1674+
14521675 var deleteTemplateUrl = adfTemplatePath + 'widget-delete.html' ;
14531676 if ( definition . deleteTemplateUrl ) {
14541677 deleteTemplateUrl = definition . deleteTemplateUrl ;
@@ -1481,6 +1704,7 @@ angular.module('adf')
14811704 // bind edit function
14821705 $scope . edit = function ( ) {
14831706 var editScope = $scope . $new ( ) ;
1707+ editScope . translate = dashboard . translate ;
14841708 editScope . definition = angular . copy ( definition ) ;
14851709
14861710 var adfEditTemplatePath = adfTemplatePath + 'widget-edit.html' ;
@@ -1573,7 +1797,7 @@ angular.module('adf')
15731797 replace : true ,
15741798 restrict : 'EA' ,
15751799 transclude : false ,
1576- templateUrl : adfTemplatePath + 'widget.html' ,
1800+ templateUrl : dashboard . customWidgetTemplatePath ? dashboard . customWidgetTemplatePath : adfTemplatePath + 'widget.html' ,
15771801 scope : {
15781802 definition : '=' ,
15791803 col : '=column' ,
0 commit comments