/*
* Search Preferences Controller
*/
-.controller('SearchPrefsCtrl',
+.controller('SearchPrefsCtrl',
['$scope','$window','$location', 'egCore', 'egOrg','egConfirmDialog', 'egAuth',
function($scope , $window , $location, egCore, egOrg, egConfirmDialog, egAuth) {
console.log('SearchPrefsCtrl');
-
-var allOrgs = [];
- var permMap = {};
- $scope.contextOrg = egCore.org.get(egCore.auth.user().ws_ou());
-
- // fetch the stored search lib info
- egCore.hatch.getItem($scope.orgList)
- .then(function(all) {
- allOrgs = all || [];
- $scope.org =
- allOrgs.map(function(w) { return w.shortname });
- return egCore.hatch.getItem('eg.search.lib.default');
- })
- .then(function(def) {
- if (def == undefined) {
- // def = $scope.orgList[0].shortname;
- egCore.hatch.setItem(
- 'eg.search.lib.default', $scope.orgList[0]);
- $scope.defaultSearchLib = $scope.orgList[0];
- def = $scope.orgList[0].shortname;
-
- //alert(" def " + def);
- // $scope.defaultSearchLib = $scope.orgList[0].shortname;
- } else {
- $scope.defaultSearchLib = def;
- //The option initially loaded will be the default Search Library
- }
- alert(def + "def 214 ");
- $scope.activeSearchLib = def; //Should we make this also show default workstation's library if no default search library exists?
- $scope.selectedOrg = def;
- });
-
$scope.orgList = egOrg.list().map(function(org) {
return {
id : org.id(),
shortname : org.shortname(),
depth : org.ou_type().depth()
+ }
+ });
+
+ egCore.hatch.getItem('eg.search.lib.default')
+ .then(function(def) {
+ if (def == undefined) {
+ egCore.hatch.setItem(
+ 'eg.search.lib.default', $scope.orgList[0]);
+ def = $scope.orgList[0].shortname;
+ }
+ //This lets our dropdown auto-select our default search lib.
+ $scope.selectedOrg = def;
+ angular.forEach($scope.orgList, function(val, key) {
+ if(JSON.stringify(def.shortname) == JSON.stringify(val.shortname)){
+ $scope.selectedOrg = val.shortname;
}
});
-
- $scope.getOrgLabel = function(org) {
- return org == $scope.defaultSearchLib ?
- egCore.strings.$replace(egCore.strings.DEFAULT_ORG_LABEL, {org:org}) : org;
+ });
+
+ $scope.getOrgLabel = function(org) {
+ return org == $scope.defaultSearchLib?
+ egCore.strings.$replace(egCore.strings.DEFAULT_ORG_LABEL, {org:org}) :org;
}
$scope.setDefaultSearchLib = function() {
egCore.hatch.setItem(
- 'eg.search.lib.default', $scope.selectedOrg)
+ 'eg.search.lib.default', JSON.parse($scope.selectedOrg))
.then(function() { $scope.defaultSearchLib = $scope.selectedOrg });
}