b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 |
|
| 2 | (function($) {
|
| 3 | $.fn.objAccountManage = function(InIt) {
|
| 4 |
|
| 5 |
|
| 6 | this.onLoad = function(flag) {
|
| 7 | if(flag) {
|
| 8 | LoadWebPage("//192.168.1.1/html/router/user_management.html");
|
| 9 |
|
| 10 | $("#lt_account_btnAddAccount").click(function() {
|
| 11 | AddNewAccount();
|
| 12 | });
|
| 13 | } //end flag
|
| 14 |
|
| 15 | GetAccountInfo();
|
| 16 | }
|
| 17 |
|
| 18 | function GetAccountInfo() {
|
| 19 | var retXml = PostXml("account","get_account");
|
| 20 | if("ERROR" == $(retXml).find("setting_response").text()) {
|
| 21 | alert("get account info error.");
|
| 22 | return;
|
| 23 | }
|
| 24 | $("tbody").empty();
|
| 25 | var accounts = $(retXml).find("accounts").text();
|
| 26 |
|
| 27 |
|
| 28 | if("" == accounts) {
|
| 29 | return;
|
| 30 | }
|
| 31 | if(accounts.charAt(accounts.length-1)) {
|
| 32 | accounts = accounts.substr(0,accounts.length-1);
|
| 33 | }
|
| 34 | var arrAccount = accounts.split(",");
|
| 35 |
|
| 36 | for(var idx = 0; idx < arrAccount.length; ++idx) {
|
| 37 | var htmlAccountEntry;
|
| 38 | if("admin" == arrAccount[idx]) {
|
| 39 | htmlAccountEntry = "<tr><td>" + arrAccount[idx] + "</td><td><a class='editAccount'>" + jQuery.i18n.prop("lEditAccount") + "</a></td></tr>";
|
| 40 | } else {
|
| 41 | htmlAccountEntry = "<tr><td>" + arrAccount[idx] + "</td><td><a class='editAccount'>" + jQuery.i18n.prop("lEditAccount")
|
| 42 | + "</a><a style='margin-left:10px;' class='delAccount'>" + jQuery.i18n.prop("lDelAccount") + "</a></td></tr>";
|
| 43 | }
|
| 44 | $("tbody").append(htmlAccountEntry);
|
| 45 |
|
| 46 | $("tbody tr:last td:last .editAccount").click(function() {
|
| 47 | EditAccount($(this).parents("tr:first").children("td:first").text());
|
| 48 | });
|
| 49 |
|
| 50 | $("tbody tr:last td:last .delAccount").click(function() {
|
| 51 | DelAccount($(this).parents("tr:first").children("td:first").text());
|
| 52 | });
|
| 53 | }
|
| 54 | }
|
| 55 |
|
| 56 | function AddNewAccount() {
|
| 57 | ShowDlg("MBAccount_Popup",200,100);
|
| 58 | $("#lt_btnSave").click(function() {
|
| 59 | if("" == $("#txtAccountPassword").val()) {
|
| 60 | showAlert("lPasswdIsEmpty");
|
| 61 | return;
|
| 62 | }
|
| 63 | if("" == $("#txtAccountName").val()) {
|
| 64 | showAlert("lAccountIsEmpty");
|
| 65 | return;
|
| 66 | }
|
| 67 | if($("#txtReAccountPassword").val() != $("#txtAccountPassword").val()) {
|
| 68 | showAlert("lPassErrorMes");
|
| 69 | return;
|
| 70 | }
|
| 71 |
|
| 72 | var configMap = new Map();
|
| 73 | configMap.put("RGW/account/user_management/action",0);
|
| 74 | configMap.put("RGW/account/user_management/username",encodeURIComponent($("#txtAccountName").val()));
|
| 75 | configMap.put("RGW/account/user_management/password",encodeURIComponent($("#txtAccountPassword").val()));
|
| 76 | CloseDlg();
|
| 77 | var retXml = PostXml("account","set_account",configMap);
|
| 78 | if("ERROR" == $(retXml).find("setting_response").text()) {
|
| 79 | alert("add account failed.");
|
| 80 | }
|
| 81 | GetAccountInfo();
|
| 82 |
|
| 83 | });
|
| 84 | }
|
| 85 |
|
| 86 | function EditAccount(account) {
|
| 87 | ShowDlg("MBAccount_Popup",200,100);
|
| 88 | $("#txtAccountName").val(account);
|
| 89 | $("#txtAccountName").attr("readonly",true);
|
| 90 | $("#txtAccountName").attr("disabled",true);
|
| 91 | $("#lt_btnSave").click(function() {
|
| 92 | if("" == $("#txtAccountPassword").val()) {
|
| 93 | showAlert("lPasswdIsEmpty");
|
| 94 | return;
|
| 95 | }
|
| 96 | if("" == $("#txtAccountName").val()) {
|
| 97 | showAlert("lAccountIsEmpty");
|
| 98 | return;
|
| 99 | }
|
| 100 | if($("#txtReAccountPassword").val() != $("#txtAccountPassword").val()) {
|
| 101 | showAlert("lPassErrorMes");
|
| 102 | return;
|
| 103 | }
|
| 104 |
|
| 105 | var configMap = new Map();
|
| 106 | configMap.put("RGW/account/user_management/action",1);
|
| 107 | configMap.put("RGW/account/user_management/username",encodeURIComponent($("#txtAccountName").val()));
|
| 108 | configMap.put("RGW/account/user_management/password",encodeURIComponent($("#txtAccountPassword").val()));
|
| 109 | CloseDlg();
|
| 110 | var retXml = PostXml("account","set_account",configMap);
|
| 111 | if("ERROR" == $(retXml).find("setting_response").text()) {
|
| 112 | alert("edit account failed.");
|
| 113 | }
|
| 114 | GetAccountInfo();
|
| 115 |
|
| 116 | });
|
| 117 | }
|
| 118 |
|
| 119 | function DelAccount(account) {
|
| 120 | var configMap = new Map();
|
| 121 | configMap.put("RGW/account/user_management/action",2);
|
| 122 | configMap.put("RGW/account/user_management/username",account);
|
| 123 | var retXml = PostXml("account","set_account",configMap);
|
| 124 | if("ERROR" == $(retXml).find("setting_response").text()) {
|
| 125 | alert("delete account failed.");
|
| 126 | }
|
| 127 | GetAccountInfo();
|
| 128 | }
|
| 129 |
|
| 130 |
|
| 131 | return this;
|
| 132 |
|
| 133 | }
|
| 134 | })(jQuery);
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|