Переглянути джерело

[security] Support for linking to Roles or Edit section

Enrico Berti 11 роки тому
батько
коміт
2bd75aaf0d

+ 5 - 5
apps/security/src/security/templates/hive.mako

@@ -310,10 +310,7 @@ ${ tree.import_templates(itemClick='$root.assist.setPath', iconClick='$root.assi
 
     $(document).ready(function () {
 
-      var _initialPath = "";
-      if (window.location.hash != "") {
-        _initialPath = window.location.hash.substr(1);
-      }
+      var _initialPath = viewModel.getPathHash();
       viewModel.init(_initialPath);
       $("#path").val(_initialPath);
 
@@ -373,6 +370,7 @@ ${ tree.import_templates(itemClick='$root.assist.setPath', iconClick='$root.assi
           $(".mainSection").hide();
           $("#" + mainSection).show();
           highlightMainMenu(mainSection);
+          viewModel.updateSectionHash(mainSection);
         }
 
         logGA(mainSection);
@@ -387,6 +385,8 @@ ${ tree.import_templates(itemClick='$root.assist.setPath', iconClick='$root.assi
         showMainSection($(this).attr("data-toggleSection"));
       });
 
+      showMainSection(viewModel.getSectionHash());
+
       var _resizeTimeout = -1;
       $(window).resize(function(){
         window.clearTimeout(_resizeTimeout);
@@ -394,7 +394,7 @@ ${ tree.import_templates(itemClick='$root.assist.setPath', iconClick='$root.assi
       });
 
       window.onpopstate = function() {
-        viewModel.assist.path(window.location.hash.substr(1));
+        viewModel.assist.path(viewModel.getPathHash());
       };
 
       $("#createRoleModal").modal({

+ 47 - 1
apps/security/static/js/hive.ko.js

@@ -209,7 +209,7 @@ var Assist = function (vm) {
 
   self.path = ko.observable("");
   self.path.subscribe(function (path) {
-    window.location.hash = path;
+    vm.updatePathHash(path);
   });
   self.server = ko.observable('');
   self.db = ko.computed(function () {
@@ -722,6 +722,52 @@ var HiveViewModel = function (initial) {
       $(document).trigger("loaded.users");
     });
   }
+
+  self.updatePathHash = function (path) {
+    var _hash = window.location.hash;
+    if (_hash.indexOf("@") == -1){
+      window.location.hash = path;
+    }
+    else {
+      window.location.hash = path + "@" + _hash.split("@")[1];
+    }
+  }
+
+  self.updateSectionHash = function (section) {
+    var _hash = window.location.hash;
+    if (_hash == ""){
+      window.location.hash = "@" + section;
+    }
+    if (_hash.indexOf("@") == -1){
+      window.location.hash = _hash + "@" + section;
+    }
+    else {
+      window.location.hash = _hash.split("@")[0] + "@" + section;
+    }
+  }
+
+  self.getPathHash = function () {
+    if (window.location.hash != "") {
+      var _hash = window.location.hash.substr(1);
+      if (_hash.indexOf("@") > -1){
+        return _hash.split("@")[0];
+      }
+      else {
+        return _hash;
+      }
+    }
+    return "";
+  }
+
+  self.getSectionHash = function () {
+    if (window.location.hash != "") {
+      var _hash = window.location.hash.substr(1);
+      if (_hash.indexOf("@") > -1){
+        return _hash.split("@")[1];
+      }
+    }
+    return "edit";
+  }
 };
 
 function logGA(page) {