Changeset 4127 for cats


Ignore:
Timestamp:
12/02/13 14:28:54 (11 years ago)
Author:
andmor
Message:

Code made compatible with minification.
JavaScrip? format and conventions

Location:
cats/SCHEMAcat/trunk/urn.org.isocat.schemacat.site/site/scripts
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cats/SCHEMAcat/trunk/urn.org.isocat.schemacat.site/site/scripts/controllers.js

    r4116 r4127  
     1'use strict';
     2
    13//SCHEMAcat angular controllers
    2 SCHEMAcat.controller('WorkspaceCtrl',
    3     [ '$scope', '$location', '$routeParams', '$timeout', 'SchemasList', 'Schema', 'UserService', 'Settings',
    4         function($scope, $location, $routeParams, $timeout, SchemasList, Schema, UserService, Settings) {   
    5    
    6             //these models have to be stored in the parent scope since they are used across page changes and
    7             //this controller is reloaded everytime the users changes page, thus reseting the $scope models.
    8             var parentScope = $scope.$parent;
    9             parentScope.pageSize = 10;
    10            
    11             //these models are stored in the local $scope since they are not used across page changes
    12             $scope.selectedSchemaIndex = $routeParams.schemaIndex;
    13 
    14             //keep the workspace page hidden until all data is loaded           
    15             $scope.animateWorkspacePageChange = 'invisible';
    16 
    17            
    18 
    19             //watch for our AJAX data to arrive and fade in workspace afterwards.
    20             //when changing page, the data is requested before the workspace controller is reloaded
    21             //so we should fade in the workspace in the new controller instance after reload.
    22             var watchListener = $scope.$watch('resultHasArrived', function (newValue, oldValue){
    23                 if(newValue) {
    24                     if(Settings.getAnimationStatus()) {
    25                         //fade in the workspace page
    26                         switch (parentScope.toNextPage){
     4SCHEMAcat.controller('WorkspaceCtrl', ['$scope', '$location', '$routeParams', '$timeout', 'SchemasList', 'Schema', 'UserService', 'Settings',
     5    function($scope, $location, $routeParams, $timeout, SchemasList, Schema, UserService, Settings) {
     6
     7        //these models have to be stored in the parent scope since they are used across page changes and
     8        //this controller is reloaded everytime the users changes page, thus reseting the $scope models.
     9        var parentScope = $scope.$parent;
     10        parentScope.pageSize = 10;
     11
     12        //these models are stored in the local $scope since they are not used across page changes
     13        $scope.selectedSchemaIndex = $routeParams.schemaIndex;
     14
     15        //keep the workspace page hidden until all data is loaded           
     16        $scope.animateWorkspacePageChange = 'invisible';
     17
     18
     19
     20        //watch for our AJAX data to arrive and fade in workspace afterwards.
     21        //when changing page, the data is requested before the workspace controller is reloaded
     22        //so we should fade in the workspace in the new controller instance after reload.
     23        var watchListener = $scope.$watch('resultHasArrived', function(newValue, oldValue) {
     24            if (newValue) {
     25                if (Settings.getAnimationStatus()) {
     26                    //fade in the workspace page
     27                    switch (parentScope.toNextPage) {
     28                        case false:
     29                            $scope.animateWorkspacePageChange = 'animated slideInLeft';
     30                            break;
     31                        case true:
     32                            $scope.animateWorkspacePageChange = 'animated slideInRight';
     33                            break;
     34                            //if it is a reload toNextPage will be undefined
     35                        default:
     36                            $scope.animateWorkspacePageChange = 'animated fadeInDown';
     37                    }
     38
     39                    $timeout(function() {
     40                        $scope.animateWorkspacePageChange = '';
     41                    }, 250);
     42                } else
     43                    $scope.animateWorkspacePageChange = '';
     44                //derregister the listener since the workspace page is now loaded
     45                watchListener();
     46            }
     47        });
     48
     49
     50        //load the schemas page and the selected schema metadata.
     51        //if reading the workspace for the first time i.e. not due to page change click
     52        if (!parentScope.workspaceFirstLoaded)
     53            loadSchemasList($routeParams.pageNumber);
     54
     55
     56        //update the current route when user clicks in another page in the paginator.
     57        //This triggers a $routeChangeStart event since we are changing the route path part.
     58        $scope.selectPage = function(page) {
     59            $location.search().schemaIndex = '0';
     60            delete $location.search().show;
     61            $location.path('workspace/page/' + page + '/').search($location.search());
     62        };
     63
     64
     65        //update the current route when the uses clicks one schema in the list. This triggers
     66        //a $routeUpdate event since we are just changing the route search part.
     67        $scope.selectSchema = function(rowIndex) {
     68            $location.search().schemaIndex = rowIndex.toString();
     69            delete $location.search().show;
     70            $location.search($location.search());
     71        };
     72
     73
     74        //listen for the $routeChangeStart event. Triggered when route path is changed (page change).
     75        $scope.$on('$routeChangeStart', function(event, next, current) {
     76            parentScope.resultHasArrived = false;
     77            if (Settings.getAnimationStatus()) {
     78                if (next.params !== undefined &&
     79                    next.params.pageNumber !== undefined &&
     80                    next.params.pageNumber > current.params.pageNumber)
     81                    parentScope.toNextPage = true;
     82                else
     83                    parentScope.toNextPage = false;
     84
     85                //slide out workspace page
     86                switch (next.templateUrl) {
     87                    case 'partials/workspace.html':
     88                        $scope.animateWorkspacePageChange =
     89                            parentScope.toNextPage ?
     90                            'animated slideOutLeft' : 'animated slideOutRight';
     91                        break;
     92                    case 'partials/contact.htm':
     93                    case 'partials/about.html':
     94                        $scope.animateWorkspacePageChange = 'animated slideOutLeft';
     95                        break;
     96                    default:
     97                        $scope.animateWorkspacePageChange = 'animated fadeOutDown';
     98                }
     99            }
     100            if (next.templateUrl === 'partials/workspace.html')
     101                loadSchemasList(next.params.pageNumber);
     102            else
     103                parentScope.workspaceFirstLoaded = false;
     104        });
     105
     106        $scope.$on('$routeChangeSuccess', function(event, current, previous) {
     107            //when coming back to the workspace from other routes, the workspace should apear from the left to the right
     108            if (Settings.getAnimationStatus()) {
     109                if (previous === undefined || previous.templateUrl === undefined ||
     110                    previous.templateUrl === 'partials/accountDetails.html')
     111                    parentScope.toNextPage = undefined;
     112            }
     113        });
     114
     115        //listen for the $routeUpdate event and update the selected schema metadata.
     116        //(if not done, the selection highlight is not updated e.g. when
     117        //navigating back and forth)
     118        $scope.$on('$routeUpdate', function(event, route) {
     119            if (route.templateUrl === 'partials/workspace.html' && route.params.schemaIndex !== $scope.selectedSchemaIndex) {
     120                parentScope.resultHasArrived = false;
     121                if (Settings.getAnimationStatus()) {
     122                    $scope.toNextSchema =
     123                        route.params.schemaIndex > $scope.selectedSchemaIndex ?
     124                        true : false;
     125
     126                    $scope.animateSchemaChange =
     127                        $scope.toNextSchema ?
     128                        'animated fadeOutUp' : 'animated fadeOutDown';
     129                    $timeout(function() {
     130                        loadSchemaMetadata(route.params.schemaIndex);
     131                    }, 250);
     132                } else
     133                    loadSchemaMetadata(route.params.schemaIndex);
     134            }
     135        });
     136
     137
     138        function loadSchemasList(page) {
     139            //check if pageNumber is not a number (can happen e.g. due to manual input)
     140            //reload on page 1 schema index 0 if so
     141            if (isNaN(parseInt(page, 10))) {
     142                $location.path('workspace/page/' + 1 + '/').search({
     143                    'schemaIndex': 0
     144                });
     145                return;
     146            }
     147
     148            //When the user changes page, the new AJAX data (next page) is requested by
     149            //the unloading controller (previous page) and used by the next loaded
     150            //controller (next page), thus we have to keep the server data across controller
     151            //reloads by saving it in the parent scope.
     152            SchemasList.get({
     153                    userID: UserService.id,
     154                    startPage: page,
     155                    pageSize: $scope.pageSize
     156                },
     157                function(result) {
     158                    //we now have the pages range so we can configure the paginator and check if pageNumber is out of
     159                    //range (can happen e.g. due to manual input) reload on page 1 schema index 0 if so
     160                    if (page > Math.ceil(result['sc:result']['sc:total-schemas'] / $scope.pageSize) ||
     161                        page < 1) {
     162                        $location.path('workspace/page/' + 1 + '/').search({
     163                            'schemaIndex': 0
     164                        });
     165                        return;
     166                    }
     167
     168                    parentScope.totalSchemaItems = result['sc:result']['sc:total-schemas'];
     169                    parentScope.currentPage = Number(page);
     170
     171
     172                    //when there is just one element we create an array with it, so ng-repeat repeats just once
     173                    parentScope.schemasList = prepareArrayForNgRepeat(result['sc:result']['sc:schemas']['sc:schema']);
     174
     175                    loadSchemaMetadata($location.search().schemaIndex);
     176
     177                    parentScope.schemasResult = result;
     178                });
     179        }
     180
     181
     182        //loads (trough a 'Schema' AJAX call) the schema metadata of the schema placed
     183        //in the 'index' position of the schemas list.
     184        function loadSchemaMetadata(index) {
     185            //if just changing the selected schema hide the metadata pane until the metadata is loaded
     186            if ($scope.animateWorkspacePageChange !== 'invisible')
     187                $scope.animateSchemaChange = 'invisible';
     188            //check if schemaIndex is out of range (can happen e.g. due to manual input)
     189            //reload on schema index 0 if so
     190            if (isNaN(parseInt(index, 10)) || index < 0 || index > $scope.schemasList.length) {
     191                $location.search({
     192                    'schemaIndex': 0
     193                });
     194                return;
     195            }
     196            //update the selected row to the route search part.
     197            $scope.selectedSchemaIndex = index;
     198
     199            //make AJAX call to get the schema metadata for the selected row
     200            var selectedSchemaRow = parentScope.schemasList[Number(index)];
     201            Schema.get({
     202                    schemaID: selectedSchemaRow['xml:id']
     203                },
     204                function(result) {
     205                    //when there is just one element we create an array with it, so ng-repeat repeats just once
     206                    parentScope.filesList = prepareArrayForNgRepeat(result['sc:schema']['sc:files']['sc:file']);
     207
     208                    if (Settings.getAnimationStatus()) {
     209                        //fade in the schema metadata
     210                        switch ($scope.toNextSchema) {
     211                            case true:
     212                                $scope.animateSchemaChange = 'animated fadeInUp';
     213                                break;
    27214                            case false:
    28                                 $scope.animateWorkspacePageChange = 'animated slideInLeft';
     215                                $scope.animateSchemaChange = 'animated fadeInDown';
    29216                                break;
    30                             case true:
    31                                 $scope.animateWorkspacePageChange = 'animated slideInRight';
    32                                 break;
    33                             //if it is a reload toNextPage will be undefined
    34                             default:
    35                                 $scope.animateWorkspacePageChange='animated fadeInDown';
     217                                //if it is a reload toNextPage will be undefined
     218                            case undefined:
     219                                $scope.animateSchemaChange = 'animated fadeInDown';
    36220                        }
    37                            
    38                         $timeout(function() {
    39                             $scope.animateWorkspacePageChange = '';
    40                         },250);
    41221                    } else
    42                         $scope.animateWorkspacePageChange = '';
    43                     //derregister the listener since the workspace page is now loaded
    44                     watchListener();
     222                        $scope.animateSchemaChange = '';
     223
     224                    parentScope.selectedSchema = result;
     225                    parentScope.resultHasArrived = true;
     226                });
     227
     228        }
     229
     230        function prepareArrayForNgRepeat(data) {
     231            var array;
     232            if (data instanceof Array)
     233                array = data;
     234            else
     235                array = new Array(data);
     236            return array;
     237        }
     238
     239        parentScope.workspaceFirstLoaded = true;
     240
     241    }
     242]);
     243
     244
     245SCHEMAcat.controller('FileController', ['$scope', '$http', '$timeout', '$location',
     246    function($scope, $http, $timeout, $location) {
     247
     248        updateShowFiles();
     249
     250        //show-hide file toggle handler
     251        $scope.showFile = function(fileName) {
     252            //update the search part of the route
     253            //triggers '$routeUpdate'
     254            $scope.showFileAjaxError = false;
     255            $timeout(function() { //(wrapping in $timeout is neded for Firefox)
     256                var locationSearch = $location.search();
     257                if ($scope.showSchemaBtn === true) {
     258                    if (locationSearch.show === undefined)
     259                        locationSearch.show = '#' + fileName;
     260                    else if (locationSearch.show.indexOf(fileName) === -1)
     261                        locationSearch.show = locationSearch.show + '#' + fileName;
     262                } else {
     263                    for (var prop in locationSearch) {
     264                        if (prop === 'show') {
     265                            var newLocationSearchShowArray = locationSearch[prop].split('#');
     266                            for (var i in newLocationSearchShowArray) {
     267                                if (newLocationSearchShowArray[i] === fileName)
     268                                    newLocationSearchShowArray.splice(i, 1);
     269                            }
     270
     271                            var newLocationSearchShowString = newLocationSearchShowArray.join('#');
     272                            if (newLocationSearchShowString !== '') {
     273                                locationSearch[prop] = newLocationSearchShowString;
     274                            } else
     275                                delete locationSearch[prop];
     276                        }
     277                    }
     278                }
     279                $location.search(locationSearch);
     280            });
     281        };
     282
     283        $scope.$on('$routeUpdate', function(event, route) {
     284            if ($scope.resultHasArrived)
     285                updateShowFiles();
     286        });
     287
     288        function updateShowFiles() {
     289            if ($location.search().show !== undefined && $location.search().show.indexOf($scope.file['sc:name']) !== -1) {
     290                $scope.showSchemaBtn = true;
     291                displayFile($scope.selectedSchema['sc:schema']['xml:id'], $scope.file['sc:name']);
     292            } else {
     293                $scope.showSchemaBtn = false;
     294                $scope.file.open = false;
     295            }
     296        }
     297
     298        function displayFile(schemaID, fileName) {
     299            if ($scope.schemaFileContent === undefined) {
     300                $http.get('/schemacat/schemas/' + schemaID + '/files/' + fileName).
     301                success(function(data, status, headers, config) {
     302                    $scope.prettify = 'prettyprint linenums';
     303
     304                    //execute prettyPrint asynchronously. We use $timeout since prettyPrint()
     305                    //must run after DOM rendering
     306                    $timeout(function() {
     307                        prettyPrint();
     308                        $scope.file.open = true;
     309                    });
     310
     311                    $scope.schemaFileContent = data;
     312                }).
     313                error(function(data, status, headers, config) {
     314                    $scope.showSchemaBtn = false;
     315                    $scope.showFile(fileName);
     316                    $scope.showFileAjaxError = true;
     317                });
     318            } else
     319                $scope.file.open = true;
     320        }
     321
     322    }
     323]);
     324
     325
     326SCHEMAcat.controller('TopMenuCtrl', ['$scope', '$modal', '$location', 'UserService', 'Settings', 'ShibService',
     327    function($scope, $modal, $location, UserService, Settings, ShibService) {
     328
     329        $scope.displayName = UserService.displayName;
     330        $scope.shibURL = ShibService.url;
     331
     332        //watch for changes in the displayName since it can be changed by the user in the account details page
     333        $scope.$watch(
     334            function() {
     335                return UserService.displayName;
     336            },
     337            function(newValue, oldValue) {
     338                if (newValue !== oldValue) {
     339                    $scope.displayName = newValue;
    45340                }
    46341            });
    47342
    48 
    49             //load the schemas page and the selected schema metadata.
    50             //if reading the workspace for the first time i.e. not due to page change click
    51             if(!parentScope.workspaceFirstLoaded)
    52                 loadSchemasList($routeParams.pageNumber);
    53 
    54 
    55             //update the current route when user clicks in another page in the paginator.
    56             //This triggers a $routeChangeStart event since we are changing the route path part.
    57             $scope.selectPage = function (page) {
    58                 $location.search().schemaIndex = '0';
    59                 delete $location.search().show;
    60                 $location.path('workspace/page/'+ page + '/').search($location.search());               
    61             };
    62 
    63 
    64             //update the current route when the uses clicks one schema in the list. This triggers
    65             //a $routeUpdate event since we are just changing the route search part.
    66             $scope.selectSchema = function (rowIndex) {       
    67                 $location.search().schemaIndex = rowIndex.toString();
    68                 delete $location.search().show;             
    69                 $location.search($location.search());
    70             };
    71            
    72            
    73             //listen for the $routeChangeStart event. Triggered when route path is changed (page change).
    74             $scope.$on("$routeChangeStart", function(event, next, current) {
    75                 parentScope.resultHasArrived = false;
    76                 if(Settings.getAnimationStatus()) {
    77                     if(next.params !== undefined &&
    78                     next.params.pageNumber !== undefined &&
    79                     next.params.pageNumber > current.params.pageNumber)
    80                         parentScope.toNextPage = true;
    81                     else
    82                         parentScope.toNextPage = false;
    83                    
    84                     //slide out workspace page
    85                     switch (next.templateUrl){
    86                         case "partials/workspace.html":
    87                             $scope.animateWorkspacePageChange =
    88                                 parentScope.toNextPage ?
    89                                 'animated slideOutLeft' :'animated slideOutRight';
    90                             break;
    91                         case "partials/contact.html":
    92                         case "partials/about.html":
    93                             $scope.animateWorkspacePageChange = 'animated slideOutLeft';
    94                             break;
    95                         default:
    96                             $scope.animateWorkspacePageChange = 'animated fadeOutDown';
    97                     }
    98                 }
    99                 if(next.templateUrl === "partials/workspace.html")
    100                     loadSchemasList(next.params.pageNumber);
    101                 else
    102                     parentScope.workspaceFirstLoaded = false;
     343        updateTopMenu();
     344
     345        $scope.isActive = function(viewLocation) {
     346            if (viewLocation === '/workspace' && $location.path().indexOf('/workspace/') !== -1)
     347                return true;
     348            return viewLocation === $location.path();
     349        };
     350
     351        $scope.updateAnimationStatus = function() {
     352            $scope.animationsChecked = !$scope.animationsChecked;
     353            if ($scope.animationsChecked)
     354                delete $location.search().animationsDisabled;
     355            else
     356                $location.search().animationsDisabled = true;
     357            $location.search($location.search());
     358        };
     359
     360        $scope.toggleTopMenu = function() {
     361            $scope.topMenuCollapsed = !$scope.topMenuCollapsed;
     362            if ($scope.topMenuCollapsed)
     363                delete $location.search().topMenuExpanded;
     364            else
     365                $location.search().topMenuExpanded = true;
     366
     367            $location.search($location.search());
     368        };
     369
     370        $scope.animationsUrlPart = function() {
     371            if ($location.search().animationsDisabled)
     372                return 'animationsDisabled';
     373            else
     374                return '';
     375        };
     376
     377        $scope.topMenuExpandedUrlPart = function() {
     378            if ($location.search().topMenuExpanded)
     379                return 'topMenuExpanded';
     380            else
     381                return '';
     382        };
     383
     384        $scope.$on('$routeUpdate', function(event, route) {
     385            updateTopMenu();
     386        });
     387
     388        //Modal window handlers and options
     389        $scope.loginClick = function() {
     390            var modalInstance = $modal.open({
     391                scope: $scope,
     392                templateUrl: 'partials/loginModal.html',
     393                controller: 'LoginModalCtrl'
    103394            });
    104            
    105             $scope.$on("$routeChangeSuccess", function(event, current, previous) {
    106                 //when coming back to the workspace from other routes, the workspace should apear from the left to the right
    107                 if(Settings.getAnimationStatus()) {
    108                     if(previous === undefined || previous.templateUrl === undefined ||
    109                       previous.templateUrl === "partials/accountDetails.html")
    110                         parentScope.toNextPage = undefined;
    111                 }
     395
     396            modalInstance.result.then(function(loginName) {
     397                alert('Now set the user cookie to [' + loginName + ']');
     398                document.cookie = 'USER=' + loginName + ';domain=;path=/';
     399                document.location.hash = '';
     400                document.location.reload(true);
    112401            });
    113            
    114             //listen for the $routeUpdate event and update the selected schema metadata.
    115             //(if not done, the selection highlight is not updated e.g. when
    116             //navigating back and forth)
    117             $scope.$on("$routeUpdate", function(event, route) {
    118                 if(route.templateUrl === "partials/workspace.html" && route.params.schemaIndex !== $scope.selectedSchemaIndex) {
    119                     parentScope.resultHasArrived = false;
    120                     if(Settings.getAnimationStatus()) {
    121                         $scope.toNextSchema =
    122                             route.params.schemaIndex > $scope.selectedSchemaIndex ?
    123                             true : false;
    124                        
    125                         $scope.animateSchemaChange =
    126                             $scope.toNextSchema ?
    127                                 'animated fadeOutUp' : 'animated fadeOutDown';
    128                         $timeout(function(){
    129                             loadSchemaMetadata(route.params.schemaIndex);
    130                         }, 250);
    131                     } else
    132                         loadSchemaMetadata(route.params.schemaIndex);
    133                 }
    134             });         
    135 
    136 
    137             function loadSchemasList(page) {
    138                 //check if pageNumber is not a number (can happen e.g. due to manual input)
    139                 //reload on page 1 schema index 0 if so
    140                 if(isNaN(parseInt(page, 10))) {
    141                         $location.path('workspace/page/'+ 1 + '/').search({'schemaIndex': 0});
    142                         return;
    143                 }
    144 
    145                 //When the user changes page, the new AJAX data (next page) is requested by
    146                 //the unloading controller (previous page) and used by the next loaded
    147                 //controller (next page), thus we have to keep the server data across controller
    148                 //reloads by saving it in the parent scope.
    149                 SchemasList.get({userID:UserService.id,
    150                     startPage:page, pageSize:$scope.pageSize},
    151                         function(result){
    152                             //we now have the pages range so we can configure the paginator and check if pageNumber is out of
    153                             //range (can happen e.g. due to manual input) reload on page 1 schema index 0 if so
    154                             if(page > Math.ceil(result['sc:result']['sc:total-schemas'] / $scope.pageSize) ||
    155                                 page < 1){
    156                                 $location.path('workspace/page/'+ 1 + '/').search({'schemaIndex': 0});
    157                                 return;
    158                             }
    159                            
    160                             parentScope.totalSchemaItems = result['sc:result']['sc:total-schemas'];
    161                             parentScope.currentPage = Number(page);
    162 
    163                            
    164                             //when there is just one element we create an array with it, so ng-repeat repeats just once
    165                             parentScope.schemasList = prepareArrayForNgRepeat(result['sc:result']['sc:schemas']['sc:schema']);
    166                            
    167                             loadSchemaMetadata($location.search().schemaIndex);
    168                            
    169                             parentScope.schemasResult = result;
    170                         });           
    171             }
    172 
    173 
    174             //loads (trough a 'Schema' AJAX call) the schema metadata of the schema placed
    175             //in the 'index' position of the schemas list.
    176             function loadSchemaMetadata(index) {
    177                 //if just changing the selected schema hide the metadata pane until the metadata is loaded
    178                 if($scope.animateWorkspacePageChange !== 'invisible')
    179                     $scope.animateSchemaChange='invisible';
    180                 //check if schemaIndex is out of range (can happen e.g. due to manual input)
    181                 //reload on schema index 0 if so
    182                 if (isNaN(parseInt(index, 10)) || index < 0 || index > $scope.schemasList.length){
    183                     $location.search({'schemaIndex': 0});
    184                     return;
    185                 }
    186                 //update the selected row to the route search part.
    187                 $scope.selectedSchemaIndex = index;
    188                
    189                 //make AJAX call to get the schema metadata for the selected row
    190                 var selectedSchemaRow = parentScope.schemasList[Number(index)];
    191                 Schema.get({schemaID:selectedSchemaRow['xml:id']},
    192                     function(result){
    193                         //when there is just one element we create an array with it, so ng-repeat repeats just once
    194                         parentScope.filesList = prepareArrayForNgRepeat(result['sc:schema']['sc:files']['sc:file']);
    195                        
    196                         if(Settings.getAnimationStatus()) {
    197                             //fade in the schema metadata
    198                             switch ($scope.toNextSchema){
    199                                 case true:
    200                                     $scope.animateSchemaChange = 'animated fadeInUp';
    201                                     break;
    202                                 case false:
    203                                     $scope.animateSchemaChange = 'animated fadeInDown';
    204                                     break;
    205                                 //if it is a reload toNextPage will be undefined
    206                                 case undefined:
    207                                     $scope.animateSchemaChange='animated fadeInDown';
    208                             }
    209                          } else
    210                             $scope.animateSchemaChange='';
    211                        
    212                         parentScope.selectedSchema = result;
    213                         parentScope.resultHasArrived = true;
    214                     });
    215                    
    216             }
    217            
    218             function prepareArrayForNgRepeat(data) {
    219                 var array;
    220                 if (data instanceof Array)
    221                         array = data;
    222                     else
    223                         array = new Array(data);
    224                     return array;
    225                 }
    226                
    227             parentScope.workspaceFirstLoaded = true;
    228                      
    229         }]);   
    230 
    231 
    232 SCHEMAcat.controller('FileController',
    233     [ '$scope', '$http', '$timeout', '$location',
    234         function($scope, $http, $timeout, $location) {
    235 
    236             updateShowFiles();
    237            
    238             //show-hide file toggle handler
    239             $scope.showFile = function (fileName){
    240                 //update the search part of the route
    241                 //triggers '$routeUpdate'
    242                 $scope.showFileAjaxError = false;
    243                 $timeout(function() { //(wrapping in $timeout is neded for Firefox)
    244                         var locationSearch = $location.search();
    245                         if($scope.showSchemaBtn === true) {
    246                             if(locationSearch.show === undefined)
    247                                 locationSearch.show = "#" + fileName;
    248                             else if(locationSearch.show.indexOf(fileName) === -1)
    249                                     locationSearch.show = locationSearch.show + "#" + fileName;
    250                         } else {                           
    251                             for (var prop in locationSearch){
    252                                 if(prop === 'show'){
    253                                     var newLocationSearchShowArray = locationSearch[prop].split('#');
    254                                     for (var i in newLocationSearchShowArray){
    255                                         if(newLocationSearchShowArray[i] === fileName)
    256                                             newLocationSearchShowArray.splice(i, 1);
    257                                     }
    258                                    
    259                                     var newLocationSearchShowString = newLocationSearchShowArray.join('#');
    260                                     if(newLocationSearchShowString !== ''){
    261                                         locationSearch[prop] = newLocationSearchShowString;
    262                                     } else
    263                                         delete locationSearch[prop];
    264                                 }
    265                               }
    266                             }
    267                         $location.search(locationSearch);
    268                         });                         
    269             };
    270                                  
    271             $scope.$on("$routeUpdate", function(event, route){
    272                 if($scope.resultHasArrived)
    273                     updateShowFiles();               
    274             });
    275            
    276             function updateShowFiles(){
    277                 if($location.search().show !== undefined && $location.search().show.indexOf($scope.file['sc:name']) !== -1){
    278                     $scope.showSchemaBtn = true;
    279                     displayFile($scope.selectedSchema['sc:schema']['xml:id'], $scope.file['sc:name']);
    280                 }                   
    281                 else {
    282                     $scope.showSchemaBtn = false;
    283                     $scope.file.open = false;
    284                 }
    285             }
    286            
    287             function displayFile(schemaID, fileName){
    288                 if($scope.schemaFileContent === undefined) {
    289                     $http.get("/schemacat/schemas/" + schemaID + "/files/" + fileName).
    290                         success(function(data, status, headers, config){
    291                             $scope.prettify = 'prettyprint linenums';
    292                                
    293                             //execute prettyPrint asynchronously. We use $timeout since prettyPrint()
    294                             //must run after DOM rendering
    295                             $timeout(function() {
    296                                 prettyPrint();
    297                                 $scope.file.open = true;
    298                             });
    299 
    300                             $scope.schemaFileContent =  data;
    301                         }).
    302                         error(function(data, status, headers, config) {
    303                             $scope.showSchemaBtn = false;
    304                             $scope.showFile(fileName);
    305                             $scope.showFileAjaxError = true;
    306                         });
    307                 } else
    308                     $scope.file.open = true;
    309             }
    310    
    311         }]);
    312 
    313  
    314 SCHEMAcat.controller('TopMenuCtrl',
    315     [ '$scope', '$modal', '$location', 'UserService', 'Settings', 'ShibService',
    316         function($scope, $modal, $location, UserService, Settings, ShibService) {
    317 
    318             $scope.displayName = UserService.displayName;
    319             $scope.shibURL = ShibService.url;
    320 
    321             //watch for changes in the displayName since it can be changed by the user in the account details page
    322             $scope.$watch(
    323                 function (){return UserService.displayName;},
    324                 function(newValue, oldValue) {
    325                     if (newValue !== oldValue) {
    326                         $scope.displayName = newValue;
    327                 }
    328             });
    329 
    330             updateTopMenu();
    331            
    332             $scope.isActive = function (viewLocation) {
    333                 if(viewLocation === "/workspace" && $location.path().indexOf("/workspace/") !== -1)
    334                     return true;         
    335                 return viewLocation === $location.path();
    336             };
    337 
    338             $scope.updateAnimationStatus = function(){
    339                 $scope.animationsChecked = !$scope.animationsChecked;
    340                 if($scope.animationsChecked)
    341                     delete $location.search().animationsDisabled;
    342                 else
    343                     $location.search().animationsDisabled = true;
    344                 $location.search($location.search());
    345             };
    346 
    347             $scope.toggleTopMenu = function(){
    348                 $scope.topMenuCollapsed = !$scope.topMenuCollapsed;
    349                 if($scope.topMenuCollapsed)
    350                     delete $location.search().topMenuExpanded;
    351                 else
    352                     $location.search().topMenuExpanded = true;   
    353                
    354                 $location.search($location.search());
    355             };
    356            
    357             $scope.animationsUrlPart = function() {
    358                 if($location.search().animationsDisabled)
    359                     return 'animationsDisabled';
    360                 else
    361                     return '';
    362             };
    363            
    364             $scope.topMenuExpandedUrlPart = function() {
    365                 if($location.search().topMenuExpanded)
    366                     return 'topMenuExpanded';
    367                 else
    368                     return '';
    369             };
    370 
    371             $scope.$on("$routeUpdate", function(event, route){
    372                 updateTopMenu();               
    373             });
    374 
    375             //Modal window handlers and options
    376             $scope.loginClick = function () {
    377                 var modalInstance = $modal.open({
    378                     scope: $scope,
    379                     templateUrl: 'partials/loginModal.html',
    380                     controller: 'LoginModalCtrl'
    381                 });
    382                
    383                 modalInstance.result.then(function (loginName) {
    384                     alert("Now set the user cookie to ["+loginName+"]");
    385                     document.cookie="USER="+loginName+";domain=;path=/";
    386                     document.location.hash = '';
    387                     document.location.reload(true);
    388                 });
    389             };
    390            
    391             function updateTopMenu(){
    392                 $scope.topMenuCollapsed = !$location.search().topMenuExpanded;
    393                
    394                 Settings.setAnimationStatus(!$location.search().animationsDisabled);
    395                 $scope.animationsChecked = Settings.getAnimationStatus();
    396             }
    397        
    398         }]);
    399 
    400 SCHEMAcat.controller('LoginModalCtrl',
    401     ['$scope', '$modalInstance',
    402         function($scope, $modalInstance) {
    403             $scope.loginClose = function () {
    404                 $modalInstance.dismiss('cancel');
    405             };
    406            
    407             //set cookie code. REMOVE in production
    408             $scope.loginSubmit = function () {
    409                 $modalInstance.close(this.loginNameInput.text);
    410             };
    411         }]);
    412 
    413 SCHEMAcat.controller('AboutPageCtrl',
    414     ['$scope', 'Settings', function($scope, Settings) {
     402        };
     403
     404        function updateTopMenu() {
     405            $scope.topMenuCollapsed = !$location.search().topMenuExpanded;
     406
     407            Settings.setAnimationStatus(!$location.search().animationsDisabled);
     408            $scope.animationsChecked = Settings.getAnimationStatus();
     409        }
     410
     411    }
     412]);
     413
     414SCHEMAcat.controller('LoginModalCtrl', ['$scope', '$modalInstance',
     415    function($scope, $modalInstance) {
     416        $scope.loginClose = function() {
     417            $modalInstance.dismiss('cancel');
     418        };
     419
     420        //set cookie code. REMOVE in production
     421        $scope.loginSubmit = function() {
     422            $modalInstance.close(this.loginNameInput.text);
     423        };
     424    }
     425]);
     426
     427SCHEMAcat.controller('AboutPageCtrl', ['$scope', 'Settings',
     428    function($scope, Settings) {
    415429
    416430        //When the user loads (or reloads) the 'About' page as the first page to be accessed, the 'toNextPage' variable
     
    420434        //governing variables are already set.
    421435        $scope.$parent.toNextPage = false;
    422        
    423         if(Settings.getAnimationStatus()) {
     436
     437        if (Settings.getAnimationStatus()) {
    424438            $scope.animateInOut = 'animated slideInRight';
    425439        }
    426        
    427         $scope.$on("$routeChangeStart", function(event, next, current) {
    428             if(Settings.getAnimationStatus()) {
    429                 switch (next.templateUrl){
    430                     case "partials/workspace.html":
     440
     441        $scope.$on('$routeChangeStart', function(event, next, current) {
     442            if (Settings.getAnimationStatus()) {
     443                switch (next.templateUrl) {
     444                    case 'partials/workspace.html':
    431445                        $scope.animateInOut = 'animated slideOutRight';
    432446                        break;
    433                     case "partials/contact.html":
     447                    case 'partials/contact.html':
    434448                        $scope.animateInOut = 'animated slideOutLeft';
    435449                        break;
     
    439453            }
    440454        });
    441        
    442         $scope.$on("$routeChangeSuccess", function(event, current, previous) {
    443                 if(Settings.getAnimationStatus()) {
    444                     var previousUrl = previous !== undefined ?
    445                         previous.templateUrl : undefined;
    446                     switch (previousUrl){
    447                         case "partials/workspace.html":
    448                             $scope.animateInOut = 'animated slideInRight';
    449                             break;
    450                         case "partials/contact.html":
    451                             $scope.animateInOut = 'animated slideInLeft';
    452                             break;
    453                         default:
    454                             $scope.animateInOut = 'animated fadeInDown';
    455                     }
     455
     456        $scope.$on('$routeChangeSuccess', function(event, current, previous) {
     457            if (Settings.getAnimationStatus()) {
     458                var previousUrl = previous !== undefined ?
     459                    previous.templateUrl : undefined;
     460                switch (previousUrl) {
     461                    case 'partials/workspace.html':
     462                        $scope.animateInOut = 'animated slideInRight';
     463                        break;
     464                    case 'partials/contact.html':
     465                        $scope.animateInOut = 'animated slideInLeft';
     466                        break;
     467                    default:
     468                        $scope.animateInOut = 'animated fadeInDown';
    456469                }
    457        });
    458     }]);
    459 
    460 SCHEMAcat.controller('ContactPageCtrl',
    461     ['$scope', 'Settings', function($scope, Settings) {
     470            }
     471        });
     472    }
     473]);
     474
     475SCHEMAcat.controller('ContactPageCtrl', ['$scope', 'Settings',
     476    function($scope, Settings) {
    462477
    463478        //When the user loads (or reloads) the 'Contact' page as the first page to be accessed, the 'toNextPage' variable
     
    467482        //governing variables are already set.
    468483        $scope.$parent.toNextPage = false;
    469        
    470         if(Settings.getAnimationStatus()) {
     484
     485        if (Settings.getAnimationStatus()) {
    471486            $scope.animateInOut = 'animated slideInRight';
    472487        }
    473        
    474         $scope.$on("$routeChangeStart", function(event, next, current) {
    475             if(Settings.getAnimationStatus()) {
    476                 switch (next.templateUrl){
    477                     case "partials/about.html":
    478                     case "partials/contact.html":
    479                     case "partials/workspace.html":
     488
     489        $scope.$on('$routeChangeStart', function(event, next, current) {
     490            if (Settings.getAnimationStatus()) {
     491                switch (next.templateUrl) {
     492                    case 'partials/about.html':
     493                    case 'partials/contact.html':
     494                    case 'partials/workspace.html':
    480495                        $scope.animateInOut = 'animated slideOutRight';
    481496                        break;
     
    485500            }
    486501        });
    487        
    488         $scope.$on("$routeChangeSuccess", function(event, current, previous) {
    489                 //when coming back to the workspace from other routes, the workspace should apear from the left to the right
    490                 if(Settings.getAnimationStatus()) {
    491                     var previousUrl = previous !== undefined ?
    492                         previous.templateUrl : undefined;
    493                     switch (previousUrl){
    494                         case "partials/about.html":
    495                         case "partials/contact.html":
    496                         case "partials/workspace.html":
    497                             $scope.animateInOut = 'animated slideInRight';
    498                             break;
    499                         default:
    500                             $scope.animateInOut = 'animated fadeInDown';
    501                     }
     502
     503        $scope.$on('$routeChangeSuccess', function(event, current, previous) {
     504            //when coming back to the workspace from other routes, the workspace should apear from the left to the right
     505            if (Settings.getAnimationStatus()) {
     506                var previousUrl = previous !== undefined ?
     507                    previous.templateUrl : undefined;
     508                switch (previousUrl) {
     509                    case 'partials/about.html':
     510                    case 'partials/contact.html':
     511                    case 'partials/workspace.html':
     512                        $scope.animateInOut = 'animated slideInRight';
     513                        break;
     514                    default:
     515                        $scope.animateInOut = 'animated fadeInDown';
    502516                }
    503         });
    504     }]);
    505    
    506     SCHEMAcat.controller('AccountDetailsPageCtrl',
    507     ['$scope', '$location', 'User', 'UserService', 'Settings', function($scope, $location, User, UserService, Settings) {
    508    
     517            }
     518        });
     519    }
     520]);
     521
     522SCHEMAcat.controller('AccountDetailsPageCtrl', ['$scope', '$location', 'User', 'UserService', 'Settings',
     523    function($scope, $location, User, UserService, Settings) {
     524
    509525        //this function is used to clean outdated emails from the route search part
    510526        //i.e. after editing an email the user can still go back in the browser but
    511527        //the old email addess does not exist anymore, thus we clean it when back is clicked.
    512         function cleanOutdatedSearchPathEmails(){
     528        function cleanOutdatedSearchPathEmails() {
    513529            var locationSearch = $location.search();
    514             for (var prop in locationSearch){
    515                 if(prop === 'edditingEmail'){
     530            for (var prop in locationSearch) {
     531                if (prop === 'edditingEmail') {
    516532                    var newLocationSearchEdditingEmailArray = locationSearch[prop].split('#');
    517                     for (var i = 0; i < newLocationSearchEdditingEmailArray.length; i++){
     533                    for (var i = 0; i < newLocationSearchEdditingEmailArray.length; i++) {
    518534                        var found = false;
    519                         for(var j = 0; j < UserService.email.length; j++){
    520                             if(newLocationSearchEdditingEmailArray[i] === UserService.email[j])
     535                        for (var j = 0; j < UserService.email.length; j++) {
     536                            if (newLocationSearchEdditingEmailArray[i] === UserService.email[j])
    521537                                found = true;
    522                             }
    523                             if(!found)
    524                                 newLocationSearchEdditingEmailArray.splice(i, 1);
     538                        }
     539                        if (!found)
     540                            newLocationSearchEdditingEmailArray.splice(i, 1);
    525541                    }
    526542                    var newLocationSearchEdditingEmailString = newLocationSearchEdditingEmailArray.join('#');
    527                     if(newLocationSearchEdditingEmailString !== ''){
     543                    if (newLocationSearchEdditingEmailString !== '') {
    528544                        locationSearch[prop] = newLocationSearchEdditingEmailString;
    529                     }
    530                     else
     545                    } else
    531546                        delete locationSearch[prop];
    532                  }
     547                }
    533548            }
    534549            $location.search(locationSearch);
    535550        }
    536        
    537         function updateEdditingDisplayName(){
     551
     552        function updateEdditingDisplayName() {
    538553            $scope.waitingForServerEditDisplayName = false;
    539554            $scope.editDisplayNameAjaxError = false;
    540             if($location.search().edditingDisplayName) {
     555            if ($location.search().edditingDisplayName) {
    541556                $scope.editDisplayNameText = $scope.displayName;
    542557                $scope.edditingDisplayName = true;
    543             }
    544             else
     558            } else
    545559                $scope.edditingDisplayName = false;
    546         } 
    547        
    548         function updateAddingEmail(){
     560        }
     561
     562        function updateAddingEmail() {
    549563            $scope.waitingForServer = false;
    550            
    551             if($location.search().addingEmail)
     564
     565            if ($location.search().addingEmail)
    552566                $scope.addingEmail = true;
    553567            else
    554568                $scope.addingEmail = false;
    555569        }
    556    
     570
    557571        $scope.principal = UserService.principal;
    558572        $scope.displayName = UserService.displayName;
    559573        $scope.email = UserService.email;
    560    
     574
    561575        $scope.addingEmail = false;
    562    
    563         $scope.addNewEmail = function (){
     576
     577        $scope.addNewEmail = function() {
    564578            $location.search().addingEmail = true;
    565579            $location.search($location.search());
    566580        };
    567        
    568         $scope.terminateAddEmail = function (){
     581
     582        $scope.terminateAddEmail = function() {
    569583            $scope.ajaxError = false;
    570584            delete $location.search().addingEmail;
    571585            $location.search($location.search());
    572586        };
    573        
    574         $scope.addEmail = function (newEmail){
     587
     588        $scope.addEmail = function(newEmail) {
    575589            $scope.waitingForServer = true;
    576             var user = new User();   
     590            var user = new User();
    577591            user.emails = UserService.email.slice(0);
    578             user.emails.push(newEmail);   
    579                
    580             user.$save({userID:UserService.id},
     592            user.emails.push(newEmail);
     593
     594            user.$save({
     595                    userID: UserService.id
     596                },
    581597                function(result) {
    582                     if(result['sc:response'] !== undefined && result['sc:response'].success){
     598                    if (result['sc:response'] !== undefined && result['sc:response'].success) {
    583599                        UserService.email.push(newEmail);
    584600                        $scope.terminateAddEmail();
    585                     }
     601                    } else {
     602                        //server reports an handeled error
     603                        $scope.waitingForServer = false;
     604                        $scope.ajaxError = true;
     605                    }
     606                },
     607                //no response, or response error flagged in http response headers
     608                function() {
     609                    $scope.waitingForServer = false;
     610                    $scope.ajaxError = true;
     611                });
     612        };
     613
     614        $scope.editDisplayName = function() {
     615            $location.search().edditingDisplayName = true;
     616            $location.search($location.search());
     617        };
     618
     619        $scope.terminateEditDisplayName = function() {
     620            delete $location.search().edditingDisplayName;
     621            $location.search($location.search());
     622        };
     623
     624        $scope.updateDisplayName = function(newDisplayName) {
     625            $scope.waitingForServerEditDisplayName = true;
     626            var user = new User();
     627            user.displayName = newDisplayName;
     628
     629            user.$save({
     630                    userID: UserService.id
     631                },
     632                function(result) {
     633                    if (result['sc:response'] !== undefined && result['sc:response'].success) {
     634                        $scope.displayName = UserService.displayName = newDisplayName;
     635                        $scope.terminateEditDisplayName();
     636                    } else {
     637                        //server reports an handeled error
     638                        $scope.waitingForServerEditDisplayName = false;
     639                        $scope.editDisplayNameAjaxError = true;
     640                    }
     641                },
     642                //no response, or response error flagged in http response headers
     643                function() {
     644                    $scope.waitingForServerEditDisplayName = false;
     645                    $scope.editDisplayNameAjaxError = true;
     646                });
     647        };
     648
     649        if (Settings.getAnimationStatus()) {
     650            $scope.animateAccountDetails = 'animated fadeInDown';
     651        }
     652
     653        $scope.$on('$routeChangeStart', function(event, next, current) {
     654            if (Settings.getAnimationStatus()) {
     655                $scope.animateAccountDetails = 'animated fadeOutUp';
     656            }
     657        });
     658
     659        $scope.$on('$routeChangeSuccess', function(event, current, previous) {
     660            if (Settings.getAnimationStatus()) {
     661                $scope.animateAccountDetails = 'animated fadeInDown';
     662            }
     663            updateAddingEmail();
     664            updateEdditingDisplayName();
     665            cleanOutdatedSearchPathEmails();
     666        });
     667
     668        $scope.$on('$routeUpdate', function(event, route) {
     669            updateAddingEmail();
     670            updateEdditingDisplayName();
     671            cleanOutdatedSearchPathEmails();
     672        });
     673    }
     674]);
     675
     676SCHEMAcat.controller('EmailInstanceCtrl', ['$scope', '$location', 'User', 'UserService',
     677    function($scope, $location, User, UserService) {
     678
     679        function updateEdditingEmail() {
     680            $scope.waitingForServerEditEmail = false;
     681            if ($location.search().edditingEmail !== undefined && $location.search().edditingEmail.indexOf($scope.emailInstance) !== -1) {
     682                $scope.editEmailText = $scope.emailInstance;
     683                $scope.edditingEmail = true;
     684            } else
     685                $scope.edditingEmail = false;
     686        }
     687
     688        updateEdditingEmail();
     689
     690        $scope.editEmail = function(emailInstance) {
     691            var locationSearch = $location.search();
     692            $scope.removeEmailAjaxError = false;
     693            if (locationSearch.edditingEmail === undefined)
     694                locationSearch.edditingEmail = emailInstance;
     695            else
     696                locationSearch.edditingEmail = $location.search().edditingEmail + '#' + emailInstance;
     697
     698            $location.search(locationSearch);
     699        };
     700
     701        $scope.removeEmail = function(index) {
     702            $scope.waitingForServerEditEmail = true;
     703
     704            var user = new User();
     705            user.emails = UserService.email.slice(0);
     706            user.emails.splice(index, 1);
     707
     708            user.$save({
     709                    userID: UserService.id
     710                },
     711                function(result) {
     712                    if (result['sc:response'] !== undefined && result['sc:response'].success) {
     713                        UserService.email.splice(index, 1);
     714                    } else {
     715                        //server reports an handeled error
     716                        $scope.waitingForServerEditEmail = false;
     717                        $scope.removeEmailAjaxError = true;
     718                    }
     719                },
     720                //no response, or response error flagged in http response headers
     721                function() {
     722                    $scope.waitingForServerEditEmail = false;
     723                    $scope.removeEmailAjaxError = true;
     724                });
     725        };
     726
     727        $scope.updateEmail = function(index) {
     728            $scope.waitingForServerEditEmail = true;
     729
     730            var user = new User();
     731            user.emails = UserService.email.slice(0);
     732            user.emails[index] = $scope.editEmailText;
     733
     734            user.$save({
     735                    userID: UserService.id
     736                },
     737                function(result) {
     738                    if (result['sc:response'] !== undefined && result['sc:response'].success) {
     739                        var newEmail = $scope.editEmailText;
     740                        $scope.cancelEditEmail(UserService.email[index]);
     741                        UserService.email[index] = newEmail;
     742                    } else {
     743                        //server reports an handeled error
     744                        $scope.waitingForServerEditEmail = false;
     745                        $scope.editEmailAjaxError = true;
     746                    }
     747                },
     748                //no response, or response error flagged in http response headers
     749                function() {
     750                    $scope.waitingForServerEditEmail = false;
     751                    $scope.editEmailAjaxError = true;
     752                });
     753        };
     754
     755
     756        $scope.cancelEditEmail = function(emailInstance) {
     757            var locationSearch = $location.search();
     758            $scope.editEmailAjaxError = false;
     759
     760            for (var prop in locationSearch) {
     761                if (prop === 'edditingEmail') {
     762                    var newLocationSearchEdditingEmailArray = locationSearch[prop].split('#');
     763                    for (var i in newLocationSearchEdditingEmailArray) {
     764                        if (newLocationSearchEdditingEmailArray[i] === emailInstance)
     765                            newLocationSearchEdditingEmailArray.splice(i, 1);
     766                    }
     767                    var newLocationSearchEdditingEmailString = newLocationSearchEdditingEmailArray.join('#');
     768                    if (newLocationSearchEdditingEmailString !== '') {
     769                        locationSearch[prop] = newLocationSearchEdditingEmailString;
     770                    } else
     771                        delete locationSearch[prop];
     772                }
     773            }
     774            $location.search(locationSearch);
     775        };
     776
     777        $scope.$on('$routeChangeSuccess', function(event, current, previous) {
     778            updateEdditingEmail();
     779        });
     780
     781        $scope.$on('$routeUpdate', function(event, route) {
     782            updateEdditingEmail();
     783        });
     784    }
     785]);
     786
     787//SCHEMAcat controlers for completeUserDetails.html page
     788SCHEMAcat.controller('CompleteUserDetailsCtrl', ['$scope', '$modal',
     789    function($scope, $modal) {
     790
     791        $scope.ajaxError = false;
     792        $scope.waitingForServer = false;
     793
     794        var userDetailsModalInstance = $modal.open({
     795            scope: $scope,
     796            backdrop: 'static',
     797            templateUrl: 'partials/fillDetailsModal.html',
     798            controller: 'CompleteUserDetailsModalCtrl'
     799        });
     800    }
     801]);
     802
     803SCHEMAcat.controller('CompleteUserDetailsModalCtrl', ['$scope', '$modalInstance', 'User', 'UserService',
     804    function($scope, $modalInstance, User, UserService) {
     805
     806        $scope.userDetailsSubmit = function() {
     807            $scope.waitingForServer = true;
     808            $scope.ajaxError = false;
     809
     810            var user = new User();
     811
     812            user.emails = [];
     813            user.emails[0] = this.emailInput.text;
     814            user.displayName = this.displayNameInput.text;
     815
     816            user.$save({
     817                    userID: UserService.id
     818                },
     819                function(result) {
     820                    if (result['sc:response'] !== undefined && result['sc:response'].success)
     821                        document.location.pathname = 'schemacat/site/index.html';
    586822                    else {
    587823                        //server reports an handeled error
     
    591827                },
    592828                //no response, or response error flagged in http response headers
    593                 function(){
     829                function() {
    594830                    $scope.waitingForServer = false;
    595831                    $scope.ajaxError = true;
    596                 });           
    597         };
    598    
    599         $scope.editDisplayName = function() {
    600             $location.search().edditingDisplayName = true;
    601             $location.search($location.search());
    602         };
    603        
    604         $scope.terminateEditDisplayName = function() {
    605             delete $location.search().edditingDisplayName;
    606             $location.search($location.search());
    607         };
    608        
    609         $scope.updateDisplayName = function(newDisplayName) {
    610             $scope.waitingForServerEditDisplayName = true;
    611             var user = new User();   
    612             user.displayName = newDisplayName;   
    613                
    614             user.$save({userID:UserService.id},
    615                 function(result) {
    616                     if(result['sc:response'] !== undefined && result['sc:response'].success){
    617                         $scope.displayName = UserService.displayName = newDisplayName;
    618                         $scope.terminateEditDisplayName();
    619                     }
    620                     else {
    621                         //server reports an handeled error
    622                         $scope.waitingForServerEditDisplayName = false;
    623                         $scope.editDisplayNameAjaxError = true;
    624                     }
    625                 },
    626                 //no response, or response error flagged in http response headers
    627                 function(){
    628                     $scope.waitingForServerEditDisplayName = false;
    629                     $scope.editDisplayNameAjaxError = true;
    630                 });           
    631         };       
    632    
    633         if(Settings.getAnimationStatus()) {
    634             $scope.animateAccountDetails = 'animated fadeInDown';
    635         }
    636        
    637         $scope.$on("$routeChangeStart", function(event, next, current) {
    638             if(Settings.getAnimationStatus()) {
    639                 $scope.animateAccountDetails = 'animated fadeOutUp';
    640             }
    641         });
    642        
    643         $scope.$on("$routeChangeSuccess", function(event, current, previous) {
    644             if(Settings.getAnimationStatus()) {
    645                 $scope.animateAccountDetails = 'animated fadeInDown';
    646             }
    647             updateAddingEmail();
    648             updateEdditingDisplayName();
    649             cleanOutdatedSearchPathEmails();
    650         });
    651        
    652         $scope.$on("$routeUpdate", function(event, route){
    653             updateAddingEmail();
    654             updateEdditingDisplayName();
    655             cleanOutdatedSearchPathEmails();
    656         });   
    657     }]);
    658    
    659     SCHEMAcat.controller('EmailInstanceCtrl',
    660     ['$scope', '$location', 'User', 'UserService',
    661         function($scope, $location, User, UserService) { 
    662        
    663             function updateEdditingEmail(){
    664                 $scope.waitingForServerEditEmail = false;
    665                 if($location.search().edditingEmail !== undefined && $location.search().edditingEmail.indexOf($scope.emailInstance) !== -1){
    666                     $scope.editEmailText = $scope.emailInstance;
    667                     $scope.edditingEmail = true;
    668                 }
    669                 else
    670                     $scope.edditingEmail = false;
    671             }
    672            
    673             updateEdditingEmail();
    674                
    675             $scope.editEmail = function (emailInstance){     
    676                 var locationSearch = $location.search();
    677                 $scope.removeEmailAjaxError = false;
    678                 if(locationSearch.edditingEmail === undefined)
    679                     locationSearch.edditingEmail = emailInstance;
    680                 else
    681                     locationSearch.edditingEmail = $location.search().edditingEmail + '#' + emailInstance;
    682                  
    683                 $location.search(locationSearch);
    684             };
    685            
    686             $scope.removeEmail = function (index){
    687                 $scope.waitingForServerEditEmail = true;
    688                              
    689                 var user = new User();   
    690                 user.emails = UserService.email.slice(0);
    691                 user.emails.splice(index, 1);
    692                    
    693                 user.$save({userID:UserService.id},
    694                     function(result) {
    695                         if(result['sc:response'] !== undefined && result['sc:response'].success){
    696                             UserService.email.splice(index, 1);
    697                         }
    698                         else {
    699                             //server reports an handeled error
    700                             $scope.waitingForServerEditEmail = false;
    701                             $scope.removeEmailAjaxError = true;
    702                         }
    703                     },
    704                     //no response, or response error flagged in http response headers
    705                     function(){
    706                         $scope.waitingForServerEditEmail = false;
    707                         $scope.removeEmailAjaxError = true;
    708                     });
    709             };
    710            
    711             $scope.updateEmail = function (index){
    712                 $scope.waitingForServerEditEmail = true;
    713                              
    714                 var user = new User();   
    715                 user.emails = UserService.email.slice(0);
    716                 user.emails[index] = $scope.editEmailText;
    717                    
    718                 user.$save({userID:UserService.id},
    719                     function(result) {
    720                         if(result['sc:response'] !== undefined && result['sc:response'].success){
    721                             var newEmail =  $scope.editEmailText;
    722                             $scope.cancelEditEmail(UserService.email[index]);
    723                             UserService.email[index] = newEmail;
    724                         }
    725                         else {
    726                             //server reports an handeled error
    727                             $scope.waitingForServerEditEmail = false;
    728                             $scope.editEmailAjaxError = true;
    729                         }
    730                     },
    731                     //no response, or response error flagged in http response headers
    732                     function(){
    733                         $scope.waitingForServerEditEmail = false;
    734                         $scope.editEmailAjaxError = true;
    735                     });
    736             };
    737            
    738            
    739             $scope.cancelEditEmail = function (emailInstance){
    740                 var locationSearch = $location.search();
    741                 $scope.editEmailAjaxError = false;
    742                
    743                 for (var prop in locationSearch){
    744                     if(prop === 'edditingEmail'){
    745                         var newLocationSearchEdditingEmailArray = locationSearch[prop].split('#');
    746                         for (var i in newLocationSearchEdditingEmailArray){
    747                             if(newLocationSearchEdditingEmailArray[i] === emailInstance)
    748                                 newLocationSearchEdditingEmailArray.splice(i, 1);
    749                             }
    750                             var newLocationSearchEdditingEmailString = newLocationSearchEdditingEmailArray.join('#');
    751                             if(newLocationSearchEdditingEmailString !== ''){
    752                                 locationSearch[prop] = newLocationSearchEdditingEmailString;
    753                             }
    754                             else
    755                                 delete locationSearch[prop];
    756                      }
    757                 }
    758                 $location.search(locationSearch);           
    759             };
    760            
    761             $scope.$on("$routeChangeSuccess", function(event, current, previous) {
    762                 updateEdditingEmail();
    763             });
    764            
    765             $scope.$on("$routeUpdate", function(event, route){
    766                 updateEdditingEmail();
    767             });
    768      }]);
    769 
    770 //SCHEMAcat controlers for completeUserDetails.html page
    771 SCHEMAcat.controller('CompleteUserDetailsCtrl',
    772     ['$scope', '$modal',
    773         function($scope, $modal) { 
    774        
    775             $scope.ajaxError = false;
    776             $scope.waitingForServer = false;
    777        
    778             var userDetailsModalInstance = $modal.open({
    779                     scope: $scope,
    780                     backdrop: 'static',
    781                     templateUrl: 'partials/fillDetailsModal.html',
    782                     controller: 'CompleteUserDetailsModalCtrl'
    783             });             
    784         }]);
    785        
    786 SCHEMAcat.controller('CompleteUserDetailsModalCtrl',
    787     ['$scope', '$modalInstance',  'User', 'UserService',
    788         function($scope, $modalInstance, User, UserService) {
    789            
    790             $scope.userDetailsSubmit = function () {
    791                 $scope.waitingForServer = true;
    792                 $scope.ajaxError = false;
    793                  
    794                 var user = new User();
    795                
    796                 user.emails = [];
    797                 user.emails[0] = this.emailInput.text;
    798                 user.displayName = this.displayNameInput.text;
    799                
    800                 user.$save({userID:UserService.id},
    801                     function(result) {
    802                         if(result['sc:response'] !== undefined && result['sc:response'].success)
    803                             document.location.pathname = "schemacat/site/index.html";
    804                         else {
    805                             //server reports an handeled error
    806                             $scope.waitingForServer = false;
    807                             $scope.ajaxError = true;
    808                         }
    809                     },
    810                     //no response, or response error flagged in http response headers
    811                     function(){
    812                         $scope.waitingForServer = false;
    813                         $scope.ajaxError = true;
    814                     });
    815             };
    816         }]);
     832                });
     833        };
     834    }
     835]);
  • cats/SCHEMAcat/trunk/urn.org.isocat.schemacat.site/site/scripts/directives.js

    r3788 r4127  
    1 SCHEMAcat.directive('workspaceDirective', [ function(){
    2     return function(scope, element, attrs) {
    3         scope.workspaceFirstLoaded = false;
    4     };
    5 }]);
     1'use strict';
     2SCHEMAcat.directive('workspaceDirective', [
     3        function() {
     4                return function(scope, element, attrs) {
     5                        scope.workspaceFirstLoaded = false;
     6                };
     7        }
     8]);
  • cats/SCHEMAcat/trunk/urn.org.isocat.schemacat.site/site/scripts/modules.js

    r4091 r4127  
     1'use strict';
     2
    13//SCHEMAcat module definition
    24var SCHEMAcat = angular.module('SCHEMAcat', ['ui.bootstrap', 'ngRoute', 'ngResource']);
    35
    4 SCHEMAcat.config( function($routeProvider) {
    5     var loadDelay = 250; //ms
    6     $routeProvider
    7         .when('/workspace/page/:pageNumber/', {
    8             controller: 'WorkspaceCtrl',
    9             templateUrl: 'partials/workspace.html',
    10            
    11             /* With this, the $routeProvider will trigger $routeChangeSuccess
     6SCHEMAcat.config(['$routeProvider',
     7    function($routeProvider) {
     8        var loadDelay = 250; //ms
     9        $routeProvider
     10            .when('/workspace/page/:pageNumber/', {
     11                controller: 'WorkspaceCtrl',
     12                templateUrl: 'partials/workspace.html',
     13
     14                /* With this, the $routeProvider will trigger $routeChangeSuccess
    1215            event if the path part (//workspace/page/:pageNumber/) is not the
    1316            same as current location, causing angular to reload the controller
     
    1821            route changes.
    1922            */
    20             reloadOnSearch: false,
    21             resolve: {
    22                 //this will cause a 0.25 second delay to allow CSS fadeOut animation to
    23                 //be displayed
    24                 delay:
    25                     function($q, $timeout, Settings) {
    26                         if(Settings.getAnimationStatus()){
    27                             var delay = $q.defer();
    28                             $timeout(delay.resolve, loadDelay);
    29                             return delay.promise;
    30                         } else
    31                             return;
    32                     }
    33             }
    34         })
    35         .when('/about', {
    36             controller: 'AboutPageCtrl',
    37             templateUrl: 'partials/about.html',
    38             reloadOnSearch: false,
    39             resolve: {
    40                 delay:
    41                     function($q, $timeout, Settings) {
    42                         if(Settings.getAnimationStatus()){
    43                             var delay = $q.defer();
    44                             $timeout(delay.resolve, loadDelay);
    45                             return delay.promise;
    46                         } else
    47                             return;
    48                     }
    49             }
    50         })
    51         .when('/contact', {
    52             controller: 'ContactPageCtrl',
    53             templateUrl: 'partials/contact.html',
    54             reloadOnSearch: false,
    55             resolve: {
    56                 delay:
    57                     function($q, $timeout, Settings) {
    58                         if(Settings.getAnimationStatus()){
    59                             var delay = $q.defer();
    60                             $timeout(delay.resolve, loadDelay);
    61                             return delay.promise;
    62                         } else
    63                             return;
    64                     }
    65             }
    66         })
    67         .when('/accountDetails', {
    68             controller: 'AccountDetailsPageCtrl',
    69             templateUrl: 'partials/accountDetails.html',
    70             reloadOnSearch: false,
    71             resolve: {
    72                 delay:
    73                     function($q, $timeout, Settings) {
    74                         if(Settings.getAnimationStatus()){
    75                             var delay = $q.defer();
    76                             $timeout(delay.resolve, loadDelay);
    77                             return delay.promise;
    78                         } else
    79                             return;
    80                     }
    81             }
    82         })
    83         .otherwise(
    84             { redirectTo: function (routeParams, path, search){
    85                 return '/workspace/page/1/?schemaIndex=0';
     23                reloadOnSearch: false,
     24                resolve: {
     25                    //this will cause a 0.25 second delay to allow CSS fadeOut animation to
     26                    //be displayed
     27                    delay: ['$q', '$timeout', 'Settings',
     28                        function($q, $timeout, Settings) {
     29                            if (Settings.getAnimationStatus()) {
     30                                var delay = $q.defer();
     31                                $timeout(delay.resolve, loadDelay);
     32                                return delay.promise;
     33                            } else
     34                                return;
     35                        }
     36                    ]
    8637                }
    87             }           
    88         );
    89 });
     38            })
     39            .when('/about', {
     40                controller: 'AboutPageCtrl',
     41                templateUrl: 'partials/about.html',
     42                reloadOnSearch: false,
     43                resolve: {
     44                    delay: ['$q', '$timeout', 'Settings',
     45                        function($q, $timeout, Settings) {
     46                            if (Settings.getAnimationStatus()) {
     47                                var delay = $q.defer();
     48                                $timeout(delay.resolve, loadDelay);
     49                                return delay.promise;
     50                            } else
     51                                return;
     52                        }
     53                    ]
     54                }
     55            })
     56            .when('/contact', {
     57                controller: 'ContactPageCtrl',
     58                templateUrl: 'partials/contact.html',
     59                reloadOnSearch: false,
     60                resolve: {
     61                    delay: ['$q', '$timeout', 'Settings',
     62                        function($q, $timeout, Settings) {
     63                            if (Settings.getAnimationStatus()) {
     64                                var delay = $q.defer();
     65                                $timeout(delay.resolve, loadDelay);
     66                                return delay.promise;
     67                            } else
     68                                return;
     69                        }
     70                    ]
     71                }
     72            })
     73            .when('/accountDetails', {
     74                controller: 'AccountDetailsPageCtrl',
     75                templateUrl: 'partials/accountDetails.html',
     76                reloadOnSearch: false,
     77                resolve: {
     78                    delay: ['$q', '$timeout', 'Settings',
     79                        function($q, $timeout, Settings) {
     80                            if (Settings.getAnimationStatus()) {
     81                                var delay = $q.defer();
     82                                $timeout(delay.resolve, loadDelay);
     83                                return delay.promise;
     84                            } else
     85                                return;
     86                        }
     87                    ]
     88                }
     89            })
     90            .otherwise({
     91                redirectTo: function(routeParams, path, search) {
     92                    return '/workspace/page/1/?schemaIndex=0';
     93                }
     94            });
     95    }
     96]);
  • cats/SCHEMAcat/trunk/urn.org.isocat.schemacat.site/site/scripts/services.js

    r3977 r4127  
     1'use strict';
    12//SCHEMAcat angular services
    2 SCHEMAcat.factory('SchemasList', function($resource){
    3     var schemasList = $resource('/schemacat/users/:userID/schemas/pagedlist/page/:startPage/pagesize/:pageSize',
    4         {userID:'guest'}
    5     );
    6     return schemasList;   
    7 });
     3SCHEMAcat.factory('SchemasList', ['$resource',
     4    function($resource) {
     5        var schemasList = $resource('/schemacat/users/:userID/schemas/pagedlist/page/:startPage/pagesize/:pageSize', {
     6            userID: 'guest'
     7        });
     8        return schemasList;
     9    }
     10]);
    811
    9 SCHEMAcat.factory('Schema', function($resource){
    10     var schema = $resource('/schemacat/schemas/:schemaID',
    11         {schemaID:''}
    12     );
    13     return schema;   
    14 });
     12SCHEMAcat.factory('Schema', ['$resource',
     13    function($resource) {
     14        var schema = $resource('/schemacat/schemas/:schemaID', {
     15            schemaID: ''
     16        });
     17        return schema;
     18    }
     19]);
    1520
    16 SCHEMAcat.factory('User', function($resource){
    17     var user = $resource('/schemacat/users/:userID',
    18         {userID:''}       
    19     );
    20     return user;   
    21 });
     21SCHEMAcat.factory('User', ['$resource',
     22    function($resource) {
     23        var user = $resource('/schemacat/users/:userID', {
     24            userID: ''
     25        });
     26        return user;
     27    }
     28]);
    2229
    23 SCHEMAcat.factory('Settings', function(){
    24     var animations = true;
    25     var objectStore = {};
    26    
    27     function _setAnimationStatus(value){
     30SCHEMAcat.factory('Settings', ['$resource',
     31    function() {
     32        var animations = true;
     33        var objectStore = {};
     34
     35        function _setAnimationStatus(value) {
    2836            animations = value;
     37        }
     38
     39        function _getAnimationStatus() {
     40            return animations;
     41        }
     42
     43        function _getStore() {
     44            return objectStore;
     45        }
     46
     47        return {
     48            getAnimationStatus: _getAnimationStatus,
     49            setAnimationStatus: _setAnimationStatus,
     50            getStore: _getStore
     51        };
    2952    }
    30    
    31     function _getAnimationStatus(){
    32             return animations; 
    33     }
    34    
    35     function _getStore(){
    36             return store; 
    37     }
    38    
    39     return {
    40         getAnimationStatus: _getAnimationStatus,
    41         setAnimationStatus: _setAnimationStatus,
    42         getStore : _getStore
    43     };
    44 });
    45 
    46  
     53]);
Note: See TracChangeset for help on using the changeset viewer.