ASR_BASE

Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/marvell/webui/www/js/panel/router/user_management.js b/marvell/webui/www/js/panel/router/user_management.js
new file mode 100644
index 0000000..56ad65d
--- /dev/null
+++ b/marvell/webui/www/js/panel/router/user_management.js
@@ -0,0 +1,138 @@
+

+(function($) {

+    $.fn.objAccountManage = function(InIt) {

+

+

+        this.onLoad = function(flag) {

+            if(flag) {

+                LoadWebPage("//192.168.1.1/html/router/user_management.html");

+

+                $("#lt_account_btnAddAccount").click(function() {

+                    AddNewAccount();

+                });

+            } //end flag

+

+            GetAccountInfo();

+        }

+

+        function GetAccountInfo() {

+            var retXml = PostXml("account","get_account");

+            if("ERROR" == $(retXml).find("setting_response").text()) {

+                alert("get account info error.");

+                return;

+            }

+            $("tbody").empty();

+            var accounts = $(retXml).find("accounts").text();

+

+

+            if("" == accounts) {

+                return;

+            }

+            if(accounts.charAt(accounts.length-1)) {

+                accounts = accounts.substr(0,accounts.length-1);

+            }

+            var arrAccount = accounts.split(",");

+

+            for(var idx = 0; idx < arrAccount.length; ++idx) {

+                var htmlAccountEntry;

+                if("admin" == arrAccount[idx]) {

+                    htmlAccountEntry = "<tr><td>" + arrAccount[idx] + "</td><td><a class='editAccount'>" + jQuery.i18n.prop("lEditAccount") + "</a></td></tr>";

+                } else {

+                    htmlAccountEntry = "<tr><td>" + arrAccount[idx] + "</td><td><a class='editAccount'>" + jQuery.i18n.prop("lEditAccount")

+                                       + "</a><a style='margin-left:10px;' class='delAccount'>" + jQuery.i18n.prop("lDelAccount") + "</a></td></tr>";

+                }

+                $("tbody").append(htmlAccountEntry);

+

+                $("tbody tr:last td:last .editAccount").click(function() {

+                    EditAccount($(this).parents("tr:first").children("td:first").text());

+                });

+

+                $("tbody tr:last td:last .delAccount").click(function() {

+                    DelAccount($(this).parents("tr:first").children("td:first").text());

+                });

+            }

+        }

+

+        function AddNewAccount() {

+            ShowDlg("MBAccount_Popup",200,100);

+            $("#lt_btnSave").click(function() {

+                if("" ==  $("#txtAccountPassword").val()) {

+                    showAlert("lPasswdIsEmpty");

+                    return;

+                }

+                if("" ==  $("#txtAccountName").val()) {

+                    showAlert("lAccountIsEmpty");

+                    return;

+                }

+                if($("#txtReAccountPassword").val() !=  $("#txtAccountPassword").val()) {

+                    showAlert("lPassErrorMes");

+                    return;

+                }

+

+                var configMap = new Map();

+                configMap.put("RGW/account/user_management/action",0);

+                configMap.put("RGW/account/user_management/username",encodeURIComponent($("#txtAccountName").val()));

+                configMap.put("RGW/account/user_management/password",encodeURIComponent($("#txtAccountPassword").val()));

+                CloseDlg();

+                var retXml = PostXml("account","set_account",configMap);

+                if("ERROR" == $(retXml).find("setting_response").text()) {

+                    alert("add account failed.");

+                }

+                GetAccountInfo();

+

+            });

+        }

+

+        function EditAccount(account) {

+            ShowDlg("MBAccount_Popup",200,100);

+            $("#txtAccountName").val(account);

+            $("#txtAccountName").attr("readonly",true);

+            $("#txtAccountName").attr("disabled",true);

+            $("#lt_btnSave").click(function() {

+                if("" ==  $("#txtAccountPassword").val()) {

+                    showAlert("lPasswdIsEmpty");

+                    return;

+                }

+                if("" ==  $("#txtAccountName").val()) {

+                    showAlert("lAccountIsEmpty");

+                    return;

+                }

+                if($("#txtReAccountPassword").val() !=  $("#txtAccountPassword").val()) {

+                    showAlert("lPassErrorMes");

+                    return;

+                }

+

+                var configMap = new Map();

+                configMap.put("RGW/account/user_management/action",1);

+                configMap.put("RGW/account/user_management/username",encodeURIComponent($("#txtAccountName").val()));

+                configMap.put("RGW/account/user_management/password",encodeURIComponent($("#txtAccountPassword").val()));

+                CloseDlg();

+                var retXml = PostXml("account","set_account",configMap);

+                if("ERROR" == $(retXml).find("setting_response").text()) {

+                    alert("edit account failed.");

+                }

+                GetAccountInfo();

+

+            });

+        }

+

+        function DelAccount(account) {

+            var configMap = new Map();

+            configMap.put("RGW/account/user_management/action",2);

+            configMap.put("RGW/account/user_management/username",account);

+            var retXml = PostXml("account","set_account",configMap);

+            if("ERROR" == $(retXml).find("setting_response").text()) {

+                alert("delete account failed.");

+            }

+            GetAccountInfo();

+        }

+

+

+        return this;

+

+    }

+})(jQuery);

+

+

+

+