LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code

Dialog Service Demo (with i18n capabilities)

(Bootstrap 3.1.1, AngularJS 1.2.16, Angular UI Bootstrap 0.11.0, Angular-Translate)

Demo of Angular dialog service using Bootstrap 3.1.1 with Angular & Angular UI Bootstrap's modal service (0.11.0).

As well as the use of Angular-Translate (https://github.com/angular-translate)

This demo shows the ability to use different languages with your dialogs as well as switch lanugages on the fly (This works for the preset dialogs only, for the custom ones you need to set that up yourself - for obvious reasons). You can also now set the size of the modal/dialog either small (sm) or large (lg), requires Bootstrap 3.1.1 and Angular-UI-Bootstrap 0.11.0. In previous versions of the "angular-dialog-service" (https://github.com/m-e-conroy/angular-dialog-service) the two way "binding" between a custom dialog and its calling controller was always decoupled, now the two way "binding" can be retained by using the "dialogsProvider.useCopy(false)."


Confirmation: {{confirmed}}

Name Enter(From Custom): {{name}}

Custom 2 Value: {{custom.val}}

Current Language: {{language}}

JS
angular.module('modalTest',['ui.bootstrap','dialogs.main','pascalprecht.translate'])
	.controller('dialogServiceTest',function($scope,$rootScope,$timeout,$translate,dialogs){
		
		//-- Variables --//
		
		$scope.lang = 'en-US';
		$scope.language = 'English';

		var _progress = 33;
		
		$scope.name = '';
		$scope.confirmed = 'No confirmation yet!';
		
		$scope.custom = {
			val: 'Initial Value'
		};
		
		//-- Listeners & Watchers --//

		$scope.$watch('lang',function(val,old){
			switch(val){
				case 'en-US':
					$scope.language = 'English';
					break;
				case 'es':
					$scope.language = 'Spanish';
					break;
			}
		});

		//-- Methods --//

		$scope.setLanguage = function(lang){
			$scope.lang = lang;
			$translate.use(lang);
		};

		$scope.launch = function(which){
			switch(which){
				case 'error':
					dialogs.error();
					break;
				case 'wait':
					var dlg = dialogs.wait(undefined,undefined,_progress);
					_fakeWaitProgress();
					break;
				case 'notify':
					dialogs.notify();
					break;
				case 'confirm':
					var dlg = dialogs.confirm();
					dlg.result.then(function(btn){
						$scope.confirmed = 'You confirmed "Yes."';
					},function(btn){
						$scope.confirmed = 'You confirmed "No."';
					});
					break;
				case 'custom':
					var dlg = dialogs.create('/dialogs/custom.html','customDialogCtrl',{},'lg');
					dlg.result.then(function(name){
						$scope.name = name;
					},function(){
						if(angular.equals($scope.name,''))
							$scope.name = 'You did not enter in your name!';
					});
					break;
				case 'custom2':
					var dlg = dialogs.create('/dialogs/custom2.html','customDialogCtrl2',$scope.custom,'lg');
					break;
			}
		}; // end launch
		
		var _fakeWaitProgress = function(){
			$timeout(function(){
				if(_progress < 100){
					_progress += 33;
					$rootScope.$broadcast('dialogs.wait.progress',{'progress' : _progress});
					_fakeWaitProgress();
				}else{
					$rootScope.$broadcast('dialogs.wait.complete');
				}
			},1000);
		};
	}) // end controller(dialogsServiceTest)
	
	.controller('customDialogCtrl',function($scope,$modalInstance,data){
		//-- Variables --//

		$scope.user = {name : ''};

		//-- Methods --//
		
		$scope.cancel = function(){
			$modalInstance.dismiss('Canceled');
		}; // end cancel
		
		$scope.save = function(){
			$modalInstance.close($scope.user.name);
		}; // end save
		
		$scope.hitEnter = function(evt){
			if(angular.equals(evt.keyCode,13) && !(angular.equals($scope.user.name,null) || angular.equals($scope.user.name,'')))
				$scope.save();
		};
	}) // end controller(customDialogCtrl)
	
	.controller('customDialogCtrl2',function($scope,$modalInstance,data){
		
		$scope.data = data;
		
		//-- Methods --//
		
		$scope.done = function(){
			$modalInstance.close($scope.data);
		}; // end done
		
	})
	
	.config(['dialogsProvider','$translateProvider',function(dialogsProvider,$translateProvider){
		dialogsProvider.useBackdrop('static');
		dialogsProvider.useEscClose(false);
		dialogsProvider.useCopy(false);
		dialogsProvider.setSize('sm');

		$translateProvider.translations('es',{
			DIALOGS_ERROR: "Error",
			DIALOGS_ERROR_MSG: "Se ha producido un error desconocido.",
			DIALOGS_CLOSE: "Cerca",
			DIALOGS_PLEASE_WAIT: "Espere por favor",
			DIALOGS_PLEASE_WAIT_ELIPS: "Espere por favor...",
			DIALOGS_PLEASE_WAIT_MSG: "Esperando en la operacion para completar.",
			DIALOGS_PERCENT_COMPLETE: "% Completado",
			DIALOGS_NOTIFICATION: "Notificacion",
			DIALOGS_NOTIFICATION_MSG: "Notificacion de aplicacion Desconocido.",
			DIALOGS_CONFIRMATION: "Confirmacion",
			DIALOGS_CONFIRMATION_MSG: "Se requiere confirmacion.",
			DIALOGS_OK: "Bueno",
			DIALOGS_YES: "Si",
			DIALOGS_NO: "No"
		});

		$translateProvider.preferredLanguage('en-US');
	}])

	.run(['$templateCache',function($templateCache){
  		$templateCache.put('/dialogs/custom.html','');
  		$templateCache.put('/dialogs/custom2.html','')
	}]);

Description

Demonstration of a dialog service using AngularJS, Bootstrap, Angular-UI-Bootstrap and Angular-Translate. Shows off Angular-Dialogs-Service version 4.2.0.
Term
Mon, 11/27/2017 - 21:29

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv