Changeset 4442


Ignore:
Timestamp:
02/05/14 10:27:31 (10 years ago)
Author:
andmor
Message:

Hidding edit access panel when user is not schema owner.
Fixed some UI refresh problems.

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

Legend:

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

    r4373 r4442  
    11'use strict';
     2
     3
     4function prepareArrayForNgRepeat(data) {
     5    var array;
     6    if (data instanceof Array)
     7        array = data;
     8    else
     9        array = new Array(data);
     10    return array;
     11}
    212
    313//SCHEMAcat angular controllers
    414SCHEMAcat.controller('WorkspaceCtrl', ['$scope', '$location', '$routeParams', '$timeout', 'SchemasList', 'Schema', 'UserService', 'Settings',
    515    function($scope, $location, $routeParams, $timeout, SchemasList, Schema, UserService, Settings) {
    6 
    7 
    8         function prepareArrayForNgRepeat(data) {
    9             var array;
    10             if (data instanceof Array)
    11                 array = data;
    12             else
    13                 array = new Array(data);
    14             return array;
    15         }
    16 
    1716
    1817        function loadSchemasList(page) {
     
    101100                    } else
    102101                        $scope.animateSchemaChange = '';
    103 
    104102                    parentScope.selectedSchema = result;
    105                     updateAccessDetailsPanel();
     103                    if ($scope.animateWorkspacePageChange === '')
     104                        updateAccessDetailsPanel();
    106105                    parentScope.resultHasArrived = true;
    107106                });
     
    109108        }
    110109
     110        function getSchemaOwnerID() {
     111            var schemaOwnerID;
     112            var authorizedUsers = prepareArrayForNgRepeat(parentScope.selectedSchema['sc:schema']['sc:access']['sc:user']);
     113            for (var i in authorizedUsers) {
     114                if (authorizedUsers[i].role === 'owner')
     115                    schemaOwnerID = authorizedUsers[i].ref;
     116            }
     117            return schemaOwnerID;
     118        }
     119
    111120
    112121        function updateAccessDetailsPanel() {
    113             $scope.workspace.editAccessForm.accessPolicy = $scope.workspace.getAccessPolicy();
     122            $scope.schemaEditable = UserService.id === getSchemaOwnerID();
     123            if ($scope.schemaEditable)
     124                $timeout(function() {
     125                    $scope.workspace.editAccessForm.accessPolicy = $scope.workspace.getAccessPolicy();
     126                });
     127            $scope.workspace.updateEditAccessPanel();
    114128            if ($location.search().showAccessDetails) {
    115129                $scope.accessDetailsPanel.open = true;
     
    157171                } else
    158172                    $scope.animateWorkspacePageChange = '';
     173                updateAccessDetailsPanel();
    159174                //derregister the listener since the workspace page is now loaded
    160                 updateAccessDetailsPanel();
    161175                watchListener();
    162176            }
     
    258272                } else
    259273                    loadSchemaMetadata(route.params.schemaIndex);
    260             }
     274            } else
     275                updateAccessDetailsPanel();
    261276        });
    262277
     
    265280]);
    266281
    267 SCHEMAcat.controller('accessDetailsPanelCtrl', ['$scope', '$location', 'Schema', 'UserService',
    268     function($scope, $location, Schema, UserService) {
     282SCHEMAcat.controller('accessDetailsPanelCtrl', ['$scope', '$location', 'Schema',
     283    function($scope, $location, Schema) {
    269284
    270285        var parentScope = $scope.$parent;
    271         parentScope.editAccessPanel = {};
    272         $scope.displayName = UserService.displayName;
    273 
    274         function updateEditAccessPanel() {
    275             if ($location.search().edditingAccess) {
    276                 parentScope.editAccessPanel.open = true;
    277             } else
    278                 parentScope.editAccessPanel.open = false;
    279             $scope.workspace.accessStatusUpdateAjaxError = false;
    280         }
     286        $scope.editAccessPanel = {};
     287        $scope.editAccessPanel.open = true;
    281288
    282289        $scope.toggleEditAccess = function() {
    283             parentScope.editAccessPanel.open = !parentScope.editAccessPanel.open;
    284             if (!parentScope.editAccessPanel.open)
     290            $scope.editAccessPanel.open = !$scope.editAccessPanel.open;
     291            if (!$scope.editAccessPanel.open)
    285292                delete $location.search().edditingAccess;
    286293            else
     
    288295
    289296            $location.search($location.search());
     297        };
     298
     299        $scope.workspace.updateEditAccessPanel = function() {
     300            if ($location.search().edditingAccess) {
     301                if (parentScope.schemaEditable)
     302                    $scope.editAccessPanel.open = true;
     303                else {
     304                    delete $location.search().edditingAccess;
     305                    $location.search($location.search());
     306                }
     307            } else
     308                $scope.editAccessPanel.open = false;
     309            $scope.workspace.accessStatusUpdateAjaxError = false;
    290310        };
    291311
     
    342362                });
    343363        };
    344 
    345         $scope.$on('$routeUpdate', function(event, route) {
    346             updateEditAccessPanel();
    347         });
    348 
    349         updateEditAccessPanel();
    350364    }
    351365]);
  • cats/SCHEMAcat/trunk/urn.org.isocat.schemacat.site/site/scripts/controllers.min.js

    r4373 r4442  
    1 "use strict";SCHEMAcat.controller("WorkspaceCtrl",["$scope","$location","$routeParams","$timeout","SchemasList","Schema","UserService","Settings",function(a,b,c,d,e,f,g,h){function i(a){var b;return b=a instanceof Array?a:new Array(a)}function j(c){return isNaN(parseInt(c,10))||1>c?(b.path("workspace/page/1/").search({schemaIndex:0}),void 0):(e.get({userID:g.id,startPage:c,pageSize:a.pageSize},function(d){return c>Math.ceil(d["sc:result"]["sc:total-schemas"]/a.pageSize)?(b.path("workspace/page/1/").search({schemaIndex:0}),void 0):(m.totalSchemaItems=d["sc:result"]["sc:total-schemas"],m.currentPage=Number(c),m.schemasList=i(d["sc:result"]["sc:schemas"]["sc:schema"]),k(b.search().schemaIndex),m.schemasResult=d,void 0)}),void 0)}function k(c){if("invisible"!==a.animateWorkspacePageChange&&(a.animateSchemaChange="invisible"),isNaN(parseInt(c,10))||0>c||c>a.schemasList.length-1)return a.selectedSchemaIndex=void 0,b.search({schemaIndex:0}),void 0;a.selectedSchemaIndex=c;var d=m.schemasList[Number(c)];f.get({schemaID:d["xml:id"]},function(b){if(m.filesList=i(b["sc:schema"]["sc:files"]["sc:file"]),h.getAnimationStatus())switch(a.toNextSchema){case!0:a.animateSchemaChange="animated fadeInUp";break;case!1:a.animateSchemaChange="animated fadeInDown";break;case void 0:a.animateSchemaChange="animated fadeInDown"}else a.animateSchemaChange="";m.selectedSchema=b,l(),m.resultHasArrived=!0})}function l(){a.workspace.editAccessForm.accessPolicy=a.workspace.getAccessPolicy(),a.accessDetailsPanel.open=b.search().showAccessDetails?!0:!1}var m=a.$parent;m.pageSize=10,a.selectedSchemaIndex=c.schemaIndex,a.animateWorkspacePageChange="invisible",a.workspace={},a.location=location;var n=a.$watch("resultHasArrived",function(b){if(b){if(h.getAnimationStatus()){switch(m.toNextPage){case!1:a.animateWorkspacePageChange="animated slideInLeft";break;case!0:a.animateWorkspacePageChange="animated slideInRight";break;default:a.animateWorkspacePageChange="animated fadeInDown"}d(function(){a.animateWorkspacePageChange=""},250)}else a.animateWorkspacePageChange="";l(),n()}});m.workspaceFirstLoaded||j(c.pageNumber),a.selectPage=function(a){b.search().schemaIndex="0",delete b.search().show,b.path("workspace.html/page/"+a+"/").search(b.search())},a.selectSchema=function(a){b.search().schemaIndex=a.toString(),delete b.search().show,b.search(b.search())},a.toggleAccessDetails=function(){a.accessDetailsPanel.open=!a.accessDetailsPanel.open,a.accessDetailsPanel.open?b.search().showAccessDetails=!0:delete b.search().showAccessDetails,b.search(b.search())},a.$on("$routeChangeStart",function(b,c,d){if(m.resultHasArrived=!1,h.getAnimationStatus())switch(m.toNextPage=void 0!==c.params&&void 0!==c.params.pageNumber&&c.params.pageNumber>d.params.pageNumber?!0:!1,c.templateUrl){case"partials/workspace.html":a.animateWorkspacePageChange=m.toNextPage?"animated slideOutLeft":"animated slideOutRight";break;case"partials/contact.html":case"partials/about.html":a.animateWorkspacePageChange="animated slideOutLeft";break;default:a.animateWorkspacePageChange="animated fadeOutDown"}"partials/workspace.html"===c.templateUrl?j(c.params.pageNumber):m.workspaceFirstLoaded=!1}),a.$on("$routeChangeSuccess",function(a,b,c){h.getAnimationStatus()&&(void 0===c||void 0===c.templateUrl||"partials/accountDetails.html"===c.templateUrl)&&(m.toNextPage=void 0)}),a.$on("$routeUpdate",function(b,c){"partials/workspace.html"===c.templateUrl&&c.params.schemaIndex!==a.selectedSchemaIndex&&(m.resultHasArrived=!1,h.getAnimationStatus()?(a.toNextSchema=c.params.schemaIndex>a.selectedSchemaIndex?!0:!1,a.animateSchemaChange=a.toNextSchema?"animated fadeOutUp":"animated fadeOutDown",d(function(){k(c.params.schemaIndex)},250)):k(c.params.schemaIndex))}),m.workspaceFirstLoaded=!0}]),SCHEMAcat.controller("accessDetailsPanelCtrl",["$scope","$location","Schema","UserService",function(a,b,c,d){function f(){e.editAccessPanel.open=b.search().edditingAccess?!0:!1,a.workspace.accessStatusUpdateAjaxError=!1}var e=a.$parent;e.editAccessPanel={},a.displayName=d.displayName,a.toggleEditAccess=function(){e.editAccessPanel.open=!e.editAccessPanel.open,e.editAccessPanel.open?b.search().edditingAccess=!0:delete b.search().edditingAccess,b.search(b.search())},a.workspace.getAccessPolicy=function(){return void 0!==e.selectedSchema["sc:schema"]["sc:access"]["sc:all"]&&"r"===e.selectedSchema["sc:schema"]["sc:access"]["sc:all"].actions?"shareURL":"private"},a.saveAccessStatus=function(b){var d=a.selectedSchema["sc:schema"]["sc:access"]["sc:user"],e=new c;switch(a.workspace.waitingForServerAccessStatusUpdate=!0,a.workspace.accessStatusUpdateAjaxError=!1,b){case"shareURL":e.access={all:{actions:"r"},user:d};break;case"private":e.access={user:d}}e.$save({schemaID:a.schemasList[a.selectedSchemaIndex]["xml:id"],schemaField:"access"},function(b){void 0!==b["sc:response"]&&b["sc:response"].success?(a.selectedSchema["sc:schema"]["sc:access"]=b["sc:response"]["sc:written-data"]["sc:access"],a.workspace.waitingForServerAccessStatusUpdate=!1):(a.workspace.waitingForServerAccessStatusUpdate=!1,a.workspace.accessStatusUpdateAjaxError=!0),a.workspace.editAccessForm.accessPolicy=a.workspace.getAccessPolicy()},function(){a.workspace.waitingForServerAccessStatusUpdate=!1,a.workspace.accessStatusUpdateAjaxError=!0,a.workspace.editAccessForm.accessPolicy=a.workspace.getAccessPolicy()})},a.$on("$routeUpdate",function(){f()}),f()}]),SCHEMAcat.controller("FileController",["$scope","$http","$timeout","$location",function(a,b,c,d){function e(){void 0!==d.search().show&&-1!==d.search().show.indexOf(a.file["sc:name"])?(a.showSchemaBtn=!0,f(a.selectedSchema["sc:schema"]["xml:id"],a.file["sc:name"])):(a.showSchemaBtn=!1,a.file.open=!1)}function f(d,e){void 0===a.schemaFileContent?b.get("/schemacat/schemas/"+d+"/files/"+e).success(function(b){a.prettify="prettyprint linenums",c(function(){prettyPrint(),a.file.open=!0}),a.schemaFileContent=b}).error(function(){a.showSchemaBtn=!1,a.showFile(e),a.showFileAjaxError=!0}):a.file.open=!0}e(),a.showFile=function(b){a.showFileAjaxError=!1,c(function(){var c=d.search();if(a.showSchemaBtn===!0)void 0===c.show?c.show="#"+b:-1===c.show.indexOf(b)&&(c.show=c.show+"#"+b);else for(var e in c)if("show"===e){var f=c[e].split("#");for(var g in f)f[g]===b&&f.splice(g,1);var h=f.join("#");""!==h?c[e]=h:delete c[e]}d.search(c)})},a.$on("$routeUpdate",function(){a.resultHasArrived&&e()})}]),SCHEMAcat.controller("TopMenuCtrl",["$scope","$modal","$location","UserService","Settings","ShibService",function(a,b,c,d,e,f){function g(){a.topMenuCollapsed=!c.search().topMenuExpanded,e.setAnimationStatus(!c.search().animationsDisabled),a.animationsChecked=e.getAnimationStatus()}a.displayName=d.displayName,a.shibURL=f.url,a.$watch(function(){return d.displayName},function(b,c){b!==c&&(a.displayName=b)}),g(),a.isActive=function(a){return"/workspace.html"===a&&-1!==c.path().indexOf("/workspace.html/")?!0:a===c.path()},a.updateAnimationStatus=function(){a.animationsChecked=!a.animationsChecked,a.animationsChecked?delete c.search().animationsDisabled:c.search().animationsDisabled=!0,c.search(c.search())},a.toggleTopMenu=function(){a.topMenuCollapsed=!a.topMenuCollapsed,a.topMenuCollapsed?delete c.search().topMenuExpanded:c.search().topMenuExpanded=!0,c.search(c.search())},a.animationsUrlPart=function(){return c.search().animationsDisabled?"animationsDisabled":""},a.topMenuExpandedUrlPart=function(){return c.search().topMenuExpanded?"topMenuExpanded":""},a.$on("$routeUpdate",function(){g()}),a.loginClick=function(){var c=b.open({scope:a,templateUrl:"partials/loginModal.html",controller:"LoginModalCtrl"});c.result.then(function(a){alert("Now set the user cookie to ["+a+"]"),document.cookie="USER="+a+";domain=;path=/",document.location.hash="",document.location.reload(!0)})}}]),SCHEMAcat.controller("LoginModalCtrl",["$scope","$modalInstance",function(a,b){a.loginClose=function(){b.dismiss("cancel")},a.loginSubmit=function(){b.close(this.loginNameInput.text)}}]),SCHEMAcat.controller("AboutPageCtrl",["$scope","Settings",function(a,b){a.$parent.toNextPage=!1,b.getAnimationStatus()&&(a.animateInOut="animated slideInRight"),a.$on("$routeChangeStart",function(c,d){if(b.getAnimationStatus())switch(d.templateUrl){case"partials/workspace.html":a.animateInOut="animated slideOutRight";break;case"partials/contact.html":a.animateInOut="animated slideOutLeft";break;default:a.animateInOut="animated fadeOutDown"}}),a.$on("$routeChangeSuccess",function(c,d,e){if(b.getAnimationStatus()){var f=void 0!==e?e.templateUrl:void 0;switch(f){case"partials/workspace.html":a.animateInOut="animated slideInRight";break;case"partials/contact.html":a.animateInOut="animated slideInLeft";break;default:a.animateInOut="animated fadeInDown"}}})}]),SCHEMAcat.controller("ContactPageCtrl",["$scope","Settings",function(a,b){a.$parent.toNextPage=!1,b.getAnimationStatus()&&(a.animateInOut="animated slideInRight"),a.$on("$routeChangeStart",function(c,d){if(b.getAnimationStatus())switch(d.templateUrl){case"partials/about.html":case"partials/contact.html":case"partials/workspace.html":a.animateInOut="animated slideOutRight";break;default:a.animateInOut="animated fadeOutDown"}}),a.$on("$routeChangeSuccess",function(c,d,e){if(b.getAnimationStatus()){var f=void 0!==e?e.templateUrl:void 0;switch(f){case"partials/about.html":case"partials/contact.html":case"partials/workspace.html":a.animateInOut="animated slideInRight";break;default:a.animateInOut="animated fadeInDown"}}})}]),SCHEMAcat.controller("AccountDetailsPageCtrl",["$scope","$location","User","UserService","Settings",function(a,b,c,d,e){function f(){var a=b.search();for(var c in a)if("edditingEmail"===c){for(var e=a[c].split("#"),f=0;f<e.length;f++){for(var g=!1,h=0;h<d.email.length;h++)e[f]===d.email[h]&&(g=!0);g||e.splice(f,1)}var i=e.join("#");""!==i?a[c]=i:delete a[c]}b.search(a)}function g(){a.waitingForServerEditDisplayName=!1,a.editDisplayNameAjaxError=!1,b.search().edditingDisplayName?(a.editDisplayNameText=a.displayName,a.edditingDisplayName=!0):a.edditingDisplayName=!1}function h(){a.waitingForServer=!1,a.addingEmail=b.search().addingEmail?!0:!1}a.principal=d.principal,a.displayName=d.displayName,a.email=d.email,a.addingEmail=!1,a.addNewEmail=function(){b.search().addingEmail=!0,b.search(b.search())},a.terminateAddEmail=function(){a.ajaxError=!1,delete b.search().addingEmail,b.search(b.search())},a.addEmail=function(b){a.waitingForServer=!0;var e=new c;e.emails=d.email.slice(0),e.emails.push(b),e.$save({userID:d.id},function(c){void 0!==c["sc:response"]&&c["sc:response"].success?(d.email.push(b),a.terminateAddEmail()):(a.waitingForServer=!1,a.ajaxError=!0)},function(){a.waitingForServer=!1,a.ajaxError=!0})},a.editDisplayName=function(){b.search().edditingDisplayName=!0,b.search(b.search())},a.terminateEditDisplayName=function(){delete b.search().edditingDisplayName,b.search(b.search())},a.updateDisplayName=function(b){a.waitingForServerEditDisplayName=!0;var e=new c;e.displayName=b,e.$save({userID:d.id},function(c){void 0!==c["sc:response"]&&c["sc:response"].success?(a.displayName=d.displayName=b,a.terminateEditDisplayName()):(a.waitingForServerEditDisplayName=!1,a.editDisplayNameAjaxError=!0)},function(){a.waitingForServerEditDisplayName=!1,a.editDisplayNameAjaxError=!0})},e.getAnimationStatus()&&(a.animateAccountDetails="animated fadeInDown"),a.$on("$routeChangeStart",function(){e.getAnimationStatus()&&(a.animateAccountDetails="animated fadeOutUp")}),a.$on("$routeChangeSuccess",function(){e.getAnimationStatus()&&(a.animateAccountDetails="animated fadeInDown"),h(),g(),f()}),a.$on("$routeUpdate",function(){h(),g(),f()})}]),SCHEMAcat.controller("EmailInstanceCtrl",["$scope","$location","User","UserService",function(a,b,c,d){function e(){a.waitingForServerEditEmail=!1,void 0!==b.search().edditingEmail&&-1!==b.search().edditingEmail.indexOf(a.emailInstance)?(a.editEmailText=a.emailInstance,a.edditingEmail=!0):a.edditingEmail=!1}e(),a.editEmail=function(c){var d=b.search();a.removeEmailAjaxError=!1,d.edditingEmail=void 0===d.edditingEmail?c:b.search().edditingEmail+"#"+c,b.search(d)},a.removeEmail=function(b){a.waitingForServerEditEmail=!0;var e=new c;e.emails=d.email.slice(0),e.emails.splice(b,1),e.$save({userID:d.id},function(c){void 0!==c["sc:response"]&&c["sc:response"].success?d.email.splice(b,1):(a.waitingForServerEditEmail=!1,a.removeEmailAjaxError=!0)},function(){a.waitingForServerEditEmail=!1,a.removeEmailAjaxError=!0})},a.updateEmail=function(b){a.waitingForServerEditEmail=!0;var e=new c;e.emails=d.email.slice(0),e.emails[b]=a.editEmailText,e.$save({userID:d.id},function(c){if(void 0!==c["sc:response"]&&c["sc:response"].success){var e=a.editEmailText;a.cancelEditEmail(d.email[b]),d.email[b]=e}else a.waitingForServerEditEmail=!1,a.editEmailAjaxError=!0},function(){a.waitingForServerEditEmail=!1,a.editEmailAjaxError=!0})},a.cancelEditEmail=function(c){var d=b.search();a.editEmailAjaxError=!1;for(var e in d)if("edditingEmail"===e){var f=d[e].split("#");for(var g in f)f[g]===c&&f.splice(g,1);var h=f.join("#");""!==h?d[e]=h:delete d[e]}b.search(d)},a.$on("$routeChangeSuccess",function(){e()}),a.$on("$routeUpdate",function(){e()})}]),SCHEMAcat.controller("CompleteUserDetailsCtrl",["$scope","$modal",function(a,b){a.ajaxError=!1,a.waitingForServer=!1,b.open({scope:a,backdrop:"static",templateUrl:"partials/fillDetailsModal.html",controller:"CompleteUserDetailsModalCtrl"})}]),SCHEMAcat.controller("CompleteUserDetailsModalCtrl",["$scope","$modalInstance","User","UserService",function(a,b,c,d){a.userDetailsSubmit=function(){a.waitingForServer=!0,a.ajaxError=!1;var b=new c;b.emails=[],b.emails[0]=this.emailInput.text,b.displayName=this.displayNameInput.text,b.$save({userID:d.id},function(b){void 0!==b["sc:response"]&&b["sc:response"].success?document.location.pathname="schemacat/site/index.html":(a.waitingForServer=!1,a.ajaxError=!0)},function(){a.waitingForServer=!1,a.ajaxError=!0})}}]);
     1"use strict";function prepareArrayForNgRepeat(a){var b;return b=a instanceof Array?a:new Array(a)}SCHEMAcat.controller("WorkspaceCtrl",["$scope","$location","$routeParams","$timeout","SchemasList","Schema","UserService","Settings",function(a,b,c,d,e,f,g,h){function i(c){return isNaN(parseInt(c,10))||1>c?(b.path("workspace/page/1/").search({schemaIndex:0}),void 0):(e.get({userID:g.id,startPage:c,pageSize:a.pageSize},function(d){return c>Math.ceil(d["sc:result"]["sc:total-schemas"]/a.pageSize)?(b.path("workspace/page/1/").search({schemaIndex:0}),void 0):(m.totalSchemaItems=d["sc:result"]["sc:total-schemas"],m.currentPage=Number(c),m.schemasList=prepareArrayForNgRepeat(d["sc:result"]["sc:schemas"]["sc:schema"]),j(b.search().schemaIndex),m.schemasResult=d,void 0)}),void 0)}function j(c){if("invisible"!==a.animateWorkspacePageChange&&(a.animateSchemaChange="invisible"),isNaN(parseInt(c,10))||0>c||c>a.schemasList.length-1)return a.selectedSchemaIndex=void 0,b.search({schemaIndex:0}),void 0;a.selectedSchemaIndex=c;var d=m.schemasList[Number(c)];f.get({schemaID:d["xml:id"]},function(b){if(m.filesList=prepareArrayForNgRepeat(b["sc:schema"]["sc:files"]["sc:file"]),h.getAnimationStatus())switch(a.toNextSchema){case!0:a.animateSchemaChange="animated fadeInUp";break;case!1:a.animateSchemaChange="animated fadeInDown";break;case void 0:a.animateSchemaChange="animated fadeInDown"}else a.animateSchemaChange="";m.selectedSchema=b,""===a.animateWorkspacePageChange&&l(),m.resultHasArrived=!0})}function k(){var a,b=prepareArrayForNgRepeat(m.selectedSchema["sc:schema"]["sc:access"]["sc:user"]);for(var c in b)"owner"===b[c].role&&(a=b[c].ref);return a}function l(){a.schemaEditable=g.id===k(),a.schemaEditable&&d(function(){a.workspace.editAccessForm.accessPolicy=a.workspace.getAccessPolicy()}),a.workspace.updateEditAccessPanel(),a.accessDetailsPanel.open=b.search().showAccessDetails?!0:!1}var m=a.$parent;m.pageSize=10,a.selectedSchemaIndex=c.schemaIndex,a.animateWorkspacePageChange="invisible",a.workspace={},a.location=location;var n=a.$watch("resultHasArrived",function(b){if(b){if(h.getAnimationStatus()){switch(m.toNextPage){case!1:a.animateWorkspacePageChange="animated slideInLeft";break;case!0:a.animateWorkspacePageChange="animated slideInRight";break;default:a.animateWorkspacePageChange="animated fadeInDown"}d(function(){a.animateWorkspacePageChange=""},250)}else a.animateWorkspacePageChange="";l(),n()}});m.workspaceFirstLoaded||i(c.pageNumber),a.selectPage=function(a){b.search().schemaIndex="0",delete b.search().show,b.path("workspace.html/page/"+a+"/").search(b.search())},a.selectSchema=function(a){b.search().schemaIndex=a.toString(),delete b.search().show,b.search(b.search())},a.toggleAccessDetails=function(){a.accessDetailsPanel.open=!a.accessDetailsPanel.open,a.accessDetailsPanel.open?b.search().showAccessDetails=!0:delete b.search().showAccessDetails,b.search(b.search())},a.$on("$routeChangeStart",function(b,c,d){if(m.resultHasArrived=!1,h.getAnimationStatus())switch(m.toNextPage=void 0!==c.params&&void 0!==c.params.pageNumber&&c.params.pageNumber>d.params.pageNumber?!0:!1,c.templateUrl){case"partials/workspace.html":a.animateWorkspacePageChange=m.toNextPage?"animated slideOutLeft":"animated slideOutRight";break;case"partials/contact.html":case"partials/about.html":a.animateWorkspacePageChange="animated slideOutLeft";break;default:a.animateWorkspacePageChange="animated fadeOutDown"}"partials/workspace.html"===c.templateUrl?i(c.params.pageNumber):m.workspaceFirstLoaded=!1}),a.$on("$routeChangeSuccess",function(a,b,c){h.getAnimationStatus()&&(void 0===c||void 0===c.templateUrl||"partials/accountDetails.html"===c.templateUrl)&&(m.toNextPage=void 0)}),a.$on("$routeUpdate",function(b,c){"partials/workspace.html"===c.templateUrl&&c.params.schemaIndex!==a.selectedSchemaIndex?(m.resultHasArrived=!1,h.getAnimationStatus()?(a.toNextSchema=c.params.schemaIndex>a.selectedSchemaIndex?!0:!1,a.animateSchemaChange=a.toNextSchema?"animated fadeOutUp":"animated fadeOutDown",d(function(){j(c.params.schemaIndex)},250)):j(c.params.schemaIndex)):l()}),m.workspaceFirstLoaded=!0}]),SCHEMAcat.controller("accessDetailsPanelCtrl",["$scope","$location","Schema",function(a,b,c){var d=a.$parent;a.editAccessPanel={},a.editAccessPanel.open=!0,a.toggleEditAccess=function(){a.editAccessPanel.open=!a.editAccessPanel.open,a.editAccessPanel.open?b.search().edditingAccess=!0:delete b.search().edditingAccess,b.search(b.search())},a.workspace.updateEditAccessPanel=function(){b.search().edditingAccess?d.schemaEditable?a.editAccessPanel.open=!0:(delete b.search().edditingAccess,b.search(b.search())):a.editAccessPanel.open=!1,a.workspace.accessStatusUpdateAjaxError=!1},a.workspace.getAccessPolicy=function(){return void 0!==d.selectedSchema["sc:schema"]["sc:access"]["sc:all"]&&"r"===d.selectedSchema["sc:schema"]["sc:access"]["sc:all"].actions?"shareURL":"private"},a.saveAccessStatus=function(b){var d=a.selectedSchema["sc:schema"]["sc:access"]["sc:user"],e=new c;switch(a.workspace.waitingForServerAccessStatusUpdate=!0,a.workspace.accessStatusUpdateAjaxError=!1,b){case"shareURL":e.access={all:{actions:"r"},user:d};break;case"private":e.access={user:d}}e.$save({schemaID:a.schemasList[a.selectedSchemaIndex]["xml:id"],schemaField:"access"},function(b){void 0!==b["sc:response"]&&b["sc:response"].success?(a.selectedSchema["sc:schema"]["sc:access"]=b["sc:response"]["sc:written-data"]["sc:access"],a.workspace.waitingForServerAccessStatusUpdate=!1):(a.workspace.waitingForServerAccessStatusUpdate=!1,a.workspace.accessStatusUpdateAjaxError=!0),a.workspace.editAccessForm.accessPolicy=a.workspace.getAccessPolicy()},function(){a.workspace.waitingForServerAccessStatusUpdate=!1,a.workspace.accessStatusUpdateAjaxError=!0,a.workspace.editAccessForm.accessPolicy=a.workspace.getAccessPolicy()})}}]),SCHEMAcat.controller("FileController",["$scope","$http","$timeout","$location",function(a,b,c,d){function e(){void 0!==d.search().show&&-1!==d.search().show.indexOf(a.file["sc:name"])?(a.showSchemaBtn=!0,f(a.selectedSchema["sc:schema"]["xml:id"],a.file["sc:name"])):(a.showSchemaBtn=!1,a.file.open=!1)}function f(d,e){void 0===a.schemaFileContent?b.get("/schemacat/schemas/"+d+"/files/"+e).success(function(b){a.prettify="prettyprint linenums",c(function(){prettyPrint(),a.file.open=!0}),a.schemaFileContent=b}).error(function(){a.showSchemaBtn=!1,a.showFile(e),a.showFileAjaxError=!0}):a.file.open=!0}e(),a.showFile=function(b){a.showFileAjaxError=!1,c(function(){var c=d.search();if(a.showSchemaBtn===!0)void 0===c.show?c.show="#"+b:-1===c.show.indexOf(b)&&(c.show=c.show+"#"+b);else for(var e in c)if("show"===e){var f=c[e].split("#");for(var g in f)f[g]===b&&f.splice(g,1);var h=f.join("#");""!==h?c[e]=h:delete c[e]}d.search(c)})},a.$on("$routeUpdate",function(){a.resultHasArrived&&e()})}]),SCHEMAcat.controller("TopMenuCtrl",["$scope","$modal","$location","UserService","Settings","ShibService",function(a,b,c,d,e,f){function g(){a.topMenuCollapsed=!c.search().topMenuExpanded,e.setAnimationStatus(!c.search().animationsDisabled),a.animationsChecked=e.getAnimationStatus()}a.displayName=d.displayName,a.shibURL=f.url,a.$watch(function(){return d.displayName},function(b,c){b!==c&&(a.displayName=b)}),g(),a.isActive=function(a){return"/workspace.html"===a&&-1!==c.path().indexOf("/workspace.html/")?!0:a===c.path()},a.updateAnimationStatus=function(){a.animationsChecked=!a.animationsChecked,a.animationsChecked?delete c.search().animationsDisabled:c.search().animationsDisabled=!0,c.search(c.search())},a.toggleTopMenu=function(){a.topMenuCollapsed=!a.topMenuCollapsed,a.topMenuCollapsed?delete c.search().topMenuExpanded:c.search().topMenuExpanded=!0,c.search(c.search())},a.animationsUrlPart=function(){return c.search().animationsDisabled?"animationsDisabled":""},a.topMenuExpandedUrlPart=function(){return c.search().topMenuExpanded?"topMenuExpanded":""},a.$on("$routeUpdate",function(){g()}),a.loginClick=function(){var c=b.open({scope:a,templateUrl:"partials/loginModal.html",controller:"LoginModalCtrl"});c.result.then(function(a){alert("Now set the user cookie to ["+a+"]"),document.cookie="USER="+a+";domain=;path=/",document.location.hash="",document.location.reload(!0)})}}]),SCHEMAcat.controller("LoginModalCtrl",["$scope","$modalInstance",function(a,b){a.loginClose=function(){b.dismiss("cancel")},a.loginSubmit=function(){b.close(this.loginNameInput.text)}}]),SCHEMAcat.controller("AboutPageCtrl",["$scope","Settings",function(a,b){a.$parent.toNextPage=!1,b.getAnimationStatus()&&(a.animateInOut="animated slideInRight"),a.$on("$routeChangeStart",function(c,d){if(b.getAnimationStatus())switch(d.templateUrl){case"partials/workspace.html":a.animateInOut="animated slideOutRight";break;case"partials/contact.html":a.animateInOut="animated slideOutLeft";break;default:a.animateInOut="animated fadeOutDown"}}),a.$on("$routeChangeSuccess",function(c,d,e){if(b.getAnimationStatus()){var f=void 0!==e?e.templateUrl:void 0;switch(f){case"partials/workspace.html":a.animateInOut="animated slideInRight";break;case"partials/contact.html":a.animateInOut="animated slideInLeft";break;default:a.animateInOut="animated fadeInDown"}}})}]),SCHEMAcat.controller("ContactPageCtrl",["$scope","Settings",function(a,b){a.$parent.toNextPage=!1,b.getAnimationStatus()&&(a.animateInOut="animated slideInRight"),a.$on("$routeChangeStart",function(c,d){if(b.getAnimationStatus())switch(d.templateUrl){case"partials/about.html":case"partials/contact.html":case"partials/workspace.html":a.animateInOut="animated slideOutRight";break;default:a.animateInOut="animated fadeOutDown"}}),a.$on("$routeChangeSuccess",function(c,d,e){if(b.getAnimationStatus()){var f=void 0!==e?e.templateUrl:void 0;switch(f){case"partials/about.html":case"partials/contact.html":case"partials/workspace.html":a.animateInOut="animated slideInRight";break;default:a.animateInOut="animated fadeInDown"}}})}]),SCHEMAcat.controller("AccountDetailsPageCtrl",["$scope","$location","User","UserService","Settings",function(a,b,c,d,e){function f(){var a=b.search();for(var c in a)if("edditingEmail"===c){for(var e=a[c].split("#"),f=0;f<e.length;f++){for(var g=!1,h=0;h<d.email.length;h++)e[f]===d.email[h]&&(g=!0);g||e.splice(f,1)}var i=e.join("#");""!==i?a[c]=i:delete a[c]}b.search(a)}function g(){a.waitingForServerEditDisplayName=!1,a.editDisplayNameAjaxError=!1,b.search().edditingDisplayName?(a.editDisplayNameText=a.displayName,a.edditingDisplayName=!0):a.edditingDisplayName=!1}function h(){a.waitingForServer=!1,a.addingEmail=b.search().addingEmail?!0:!1}a.principal=d.principal,a.displayName=d.displayName,a.email=d.email,a.addingEmail=!1,a.addNewEmail=function(){b.search().addingEmail=!0,b.search(b.search())},a.terminateAddEmail=function(){a.ajaxError=!1,delete b.search().addingEmail,b.search(b.search())},a.addEmail=function(b){a.waitingForServer=!0;var e=new c;e.emails=d.email.slice(0),e.emails.push(b),e.$save({userID:d.id},function(c){void 0!==c["sc:response"]&&c["sc:response"].success?(d.email.push(b),a.terminateAddEmail()):(a.waitingForServer=!1,a.ajaxError=!0)},function(){a.waitingForServer=!1,a.ajaxError=!0})},a.editDisplayName=function(){b.search().edditingDisplayName=!0,b.search(b.search())},a.terminateEditDisplayName=function(){delete b.search().edditingDisplayName,b.search(b.search())},a.updateDisplayName=function(b){a.waitingForServerEditDisplayName=!0;var e=new c;e.displayName=b,e.$save({userID:d.id},function(c){void 0!==c["sc:response"]&&c["sc:response"].success?(a.displayName=d.displayName=b,a.terminateEditDisplayName()):(a.waitingForServerEditDisplayName=!1,a.editDisplayNameAjaxError=!0)},function(){a.waitingForServerEditDisplayName=!1,a.editDisplayNameAjaxError=!0})},e.getAnimationStatus()&&(a.animateAccountDetails="animated fadeInDown"),a.$on("$routeChangeStart",function(){e.getAnimationStatus()&&(a.animateAccountDetails="animated fadeOutUp")}),a.$on("$routeChangeSuccess",function(){e.getAnimationStatus()&&(a.animateAccountDetails="animated fadeInDown"),h(),g(),f()}),a.$on("$routeUpdate",function(){h(),g(),f()})}]),SCHEMAcat.controller("EmailInstanceCtrl",["$scope","$location","User","UserService",function(a,b,c,d){function e(){a.waitingForServerEditEmail=!1,void 0!==b.search().edditingEmail&&-1!==b.search().edditingEmail.indexOf(a.emailInstance)?(a.editEmailText=a.emailInstance,a.edditingEmail=!0):a.edditingEmail=!1}e(),a.editEmail=function(c){var d=b.search();a.removeEmailAjaxError=!1,d.edditingEmail=void 0===d.edditingEmail?c:b.search().edditingEmail+"#"+c,b.search(d)},a.removeEmail=function(b){a.waitingForServerEditEmail=!0;var e=new c;e.emails=d.email.slice(0),e.emails.splice(b,1),e.$save({userID:d.id},function(c){void 0!==c["sc:response"]&&c["sc:response"].success?d.email.splice(b,1):(a.waitingForServerEditEmail=!1,a.removeEmailAjaxError=!0)},function(){a.waitingForServerEditEmail=!1,a.removeEmailAjaxError=!0})},a.updateEmail=function(b){a.waitingForServerEditEmail=!0;var e=new c;e.emails=d.email.slice(0),e.emails[b]=a.editEmailText,e.$save({userID:d.id},function(c){if(void 0!==c["sc:response"]&&c["sc:response"].success){var e=a.editEmailText;a.cancelEditEmail(d.email[b]),d.email[b]=e}else a.waitingForServerEditEmail=!1,a.editEmailAjaxError=!0},function(){a.waitingForServerEditEmail=!1,a.editEmailAjaxError=!0})},a.cancelEditEmail=function(c){var d=b.search();a.editEmailAjaxError=!1;for(var e in d)if("edditingEmail"===e){var f=d[e].split("#");for(var g in f)f[g]===c&&f.splice(g,1);var h=f.join("#");""!==h?d[e]=h:delete d[e]}b.search(d)},a.$on("$routeChangeSuccess",function(){e()}),a.$on("$routeUpdate",function(){e()})}]),SCHEMAcat.controller("CompleteUserDetailsCtrl",["$scope","$modal",function(a,b){a.ajaxError=!1,a.waitingForServer=!1,b.open({scope:a,backdrop:"static",templateUrl:"partials/fillDetailsModal.html",controller:"CompleteUserDetailsModalCtrl"})}]),SCHEMAcat.controller("CompleteUserDetailsModalCtrl",["$scope","$modalInstance","User","UserService",function(a,b,c,d){a.userDetailsSubmit=function(){a.waitingForServer=!0,a.ajaxError=!1;var b=new c;b.emails=[],b.emails[0]=this.emailInput.text,b.displayName=this.displayNameInput.text,b.$save({userID:d.id},function(b){void 0!==b["sc:response"]&&b["sc:response"].success?document.location.pathname="schemacat/site/index.html":(a.waitingForServer=!1,a.ajaxError=!0)},function(){a.waitingForServer=!1,a.ajaxError=!0})}}]);
Note: See TracChangeset for help on using the changeset viewer.