summaryrefslogtreecommitdiff
path: root/www/js/WizardCtrl.js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js/WizardCtrl.js')
-rw-r--r--www/js/WizardCtrl.js167
1 files changed, 167 insertions, 0 deletions
diff --git a/www/js/WizardCtrl.js b/www/js/WizardCtrl.js
new file mode 100644
index 00000000..8dacfee7
--- /dev/null
+++ b/www/js/WizardCtrl.js
@@ -0,0 +1,167 @@
+/* jshint -W041 */
+/* jslint browser: true*/
+/* global cordova,StatusBar,angular,console, Masonry, URI */
+
+angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$rootScope', '$ionicModal', 'ZMDataModel','$ionicSideMenuDelegate', '$ionicHistory', '$state', '$ionicPopup', 'SecuredPopups',function ($scope, $rootScope, $ionicModal, ZMDataModel,$ionicSideMenuDelegate, $ionicHistory, $state, $ionicPopup, SecuredPopups) {
+$scope.openMenu = function () {
+ $ionicSideMenuDelegate.toggleLeft();
+ };
+
+
+
+ function addhttp(url) {
+
+ if ((!/^(f|ht)tps?:\/\//i.test(url)) && (url != "")) {
+ url = "http://" + url;
+ }
+ return url;
+ }
+
+ function validURL(url)
+ {
+ if (!url)
+
+ return ({status:false, code:"URL cannot be empty"});
+ url = addhttp(url);
+ return ({status:true, code:""});
+
+ }
+
+
+ $scope.exitAuth = function()
+ {
+ ZMDataModel.zmLog ("Wizard: validating auth syntax");
+ if ($scope.wizard.useauth)
+ {
+ if (!$scope.wizard.usezmauth && !$scope.wizard.usebasicauth)
+ {
+ $rootScope.zmPopup = SecuredPopups.show('show',{
+ title: 'Whoops!',
+ template: 'You need to enable at least one authentication mechanism',
+ buttons: [{text: 'Ok'}]
+
+ });
+ return false;
+ }
+ if ($scope.wizard.usezmauth)
+ {
+ if ((!$scope.wizard.zmuser) || (!$scope.wizard.zmpassword))
+ {
+ $rootScope.zmPopup = SecuredPopups.show('show',{
+ title: 'Whoops!',
+ template: 'Please enter a valid username and password for ZM auth',
+ buttons: [{text: 'Ok'}]
+
+ });
+ return false;
+ }
+ }
+
+ if ($scope.wizard.usebasicauth)
+ {
+ if ((!$scope.wizard.basicuser) || (!$scope.wizard.basicpassword))
+ {
+ $rootScope.zmPopup = SecuredPopups.show('show',{
+ title: 'Whoops!',
+ template: 'Please enter a valid username and password for basic auth',
+ buttons: [{text: 'Ok'}]
+
+ });
+ return false;
+ }
+ }
+ }
+ return true;
+
+ };
+
+ $scope.exitPortal = function()
+ {
+ ZMDataModel.zmLog ("Wizard: validating portal url syntax");
+
+ if (!$scope.wizard.portalurl)
+ {
+ $rootScope.zmPopup = SecuredPopups.show('show',{
+ title: 'Whoops!',
+ template: 'Portal url cannot be empty',
+ buttons: [{text: 'Ok'}]
+
+ });
+ return false;
+ }
+
+ $scope.wizard.portalurl = $scope.wizard.portalurl.toLowerCase().trim();
+ $scope.wizard.portalurl = addhttp($scope.wizard.portalurl);
+ ZMDataModel.zmLog ("Wizard: stripped url:"+$scope.wizard.portalurl);
+
+ var c = URI.parse ($scope.wizard.portalurl);
+
+ if (!c.scheme)
+ {
+ $rootScope.zmPopup = SecuredPopups.show('show',{
+ title: 'Whoops!',
+ template: 'URL seems invalid (no protocol detected)',
+ buttons: [{text: 'Ok'}]
+
+ });
+ return false;
+ }
+
+
+ if (c.userinfo) // basic auth stuff in here, take it out and put it into the next screen
+ {
+ $scope.wizard.useauth = true;
+ $scope.wizard.usebasicauth = true;
+ var barray = c.userinfo.split(":",2);
+ $scope.wizard.basicuser = barray[0];
+ $scope.wizard.basicpassword = barray[1];
+ }
+
+ $scope.wizard.portalurl = c.scheme+"://";
+ if (c.host) $scope.wizard.portalurl += c.host;
+ if (c.port) $scope.wizard.portalurl += ":"+c.host;
+ if (c.path) $scope.wizard.portalurl += c.path;
+ ZMDataModel.zmLog ("Wizard: normalized url:"+$scope.wizard.portalurl);
+ return true;
+ };
+
+ $scope.toggleAuth = function()
+ {
+ $scope.wizard.useauth = !$scope.wizard.useauth;
+ if (!$scope.wizard.useauth)
+ {
+ $scope.wizard.usebasicauth = false;
+ $scope.wizard.usezmauth = false;
+ }
+ };
+
+
+ $scope.toggleTip = function()
+ {
+ $scope.wizard.tipshow = !$scope.wizard.tipshow;
+ if ($scope.wizard.tipshow)
+ $scope.wizard.tiptext = "hide tip";
+ else
+ $scope.wizard.tiptext = "show tip";
+ };
+
+
+ $scope.$on('$ionicView.enter', function () {
+ //console.log("**VIEW ** Help Ctrl Entered");
+
+ $scope.wizard = {
+ tipshow:false,
+ tiptext:"show tip",
+ useauth:false,
+ usebasicauth:false,
+ usezmauth:false,
+ portalurl: "",
+ basicuser : "",
+ basicpassword : "",
+ zmuser : "",
+ zmpassword : ""
+ };
+
+ });
+
+}]);