puzhibing
2023-06-13 7860e5cb6db60aeb82c640651998f8294635df5b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/**
 * 角色详情对话框(可用于添加和修改对话框)
 */
var language =$("#language").val()
var RolInfoDlg = {
    roleInfoData: {},
    deptZtree: null,
    pNameZtree: null,
    validateFields: {
        name: {
            validators: {
                notEmpty: {
                    message: language==1?'用户名不能为空':(language==2?"The user name cannot be empty":"Nama pengguna tidak dapat kosong")
                }
            }
        },
        tips: {
            validators: {
                notEmpty: {
                    message: language==1?'别名不能为空':(language==2?"The alias cannot be empty":"Alias tidak dapat kosong")
                }
            }
        }/*,
        pName: {
            validators: {
                notEmpty: {
                    message: '父级名称不能为空'
                }
            }
        }*/
    }
};
 
/**
 * 清除数据
 */
RolInfoDlg.clearData = function () {
    this.roleInfoData = {};
};
 
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
RolInfoDlg.set = function (key, value) {
    this.roleInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
    return this;
};
 
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
RolInfoDlg.get = function (key) {
    return $("#" + key).val();
};
 
/**
 * 关闭此对话框
 */
RolInfoDlg.close = function () {
    parent.layer.close(window.parent.Role.layerIndex);
};
 
/**
 * 点击部门input框时
 *
 * @param e
 * @param treeId
 * @param treeNode
 * @returns
 */
RolInfoDlg.onClickDept = function (e, treeId, treeNode) {
    $("#deptName").attr("value", RolInfoDlg.deptZtree.getSelectedVal());
    $("#deptid").attr("value", treeNode.id);
};
RolInfoDlg.onDblClickDept = function (e, treeId, treeNode) {
    $("#deptName").attr("value", RolInfoDlg.deptZtree.getSelectedVal());
    $("#deptid").attr("value", treeNode.id);
    $("#deptContent").fadeOut("fast");
};
 
/**
 * 点击父级菜单input框时
 *
 * @param e
 * @param treeId
 * @param treeNode
 * @returns
 */
RolInfoDlg.onClickPName = function (e, treeId, treeNode) {
    $("#pName").attr("value", RolInfoDlg.pNameZtree.getSelectedVal());
    $("#pid").attr("value", treeNode.id);
};
 
/**
 * 显示部门选择的树
 *
 * @returns
 */
RolInfoDlg.showDeptSelectTree = function () {
    Feng.showInputTree("deptName", "deptContent");
};
 
/**
 * 显示父级菜单的树
 *
 * @returns
 */
RolInfoDlg.showPNameSelectTree = function () {
    Feng.showInputTree("pName", "pNameContent");
};
 
/**
 * 收集数据
 */
RolInfoDlg.collectData = function () {
    this.set('id').set('name').set('pid').set('deptid').set('tips').set('num');
};
 
/**
 * 验证数据是否为空
 */
RolInfoDlg.validate = function () {
    $('#roleInfoForm').data("bootstrapValidator").resetForm();
    $('#roleInfoForm').bootstrapValidator('validate');
    return $("#roleInfoForm").data('bootstrapValidator').isValid();
};
 
/**
 * 提交添加用户
 */
RolInfoDlg.addSubmit = function () {
 
    this.clearData();
    this.collectData();
 
    if (!this.validate()) {
        return;
    }
    var pName = $("#pName").val();
    if ("" == pName){
        if(language==1){
            Feng.info("上级名称不能为空");
        }else if(language==2){
            Feng.info("The parent name cannot be empty");
        }else {
            Feng.info("Nama orang tua tidak dapat kosong");
        }
 
        return;
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/role/add", function (data) {
          if(language==1){
            Feng.success("添加成功!");
        }else if(language==2){
            Feng.success("Successfully added!");
        }else {
            Feng.success("Sangat berhasil ditambah!");
        }
        window.parent.Role.table.refresh();
        RolInfoDlg.close();
    }, function (data) {
        if(language==1){
            Feng.error("添加失败!" + data.responseJSON.message + "!");
        }else if(language==2){
            Feng.error("Fail to add!" + data.responseJSON.message + "!");
        }else {
            Feng.error("Gagal menambah!" + data.responseJSON.message + "!");
        }
    });
    ajax.set(this.roleInfoData);
    ajax.start();
};
 
/**
 * 提交修改
 */
RolInfoDlg.editSubmit = function () {
 
    this.clearData();
    this.collectData();
 
    if (!this.validate()) {
        return;
    }
    var pName = $("#pName").val();
    if ("" == pName){
        if(language==1){
            Feng.info("上级名称不能为空");
        }else if(language==2){
            Feng.info("The parent name cannot be empty");
        }else {
            Feng.info("Nama orang tua tidak dapat kosong");
        }
        return;
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/role/edit", function (data) {
        if(language==1){
            Feng.success("修改成功!");
        }else if(language==2){
            Feng.success("Modify successfully!");
        }else {
            Feng.success("Mengubah dengan sukses!");
        }
        window.parent.Role.table.refresh();
        RolInfoDlg.close();
    }, function (data) {
        if(language==1){
            Feng.error("修改失败!" + data.responseJSON.message + "!");
        }else if(language==2){
            Feng.error("Fail to modify!" + data.responseJSON.message + "!");
        }else {
            Feng.error("Gagal mengubah!" + data.responseJSON.message + "!");;
        }
    });
    ajax.set(this.roleInfoData);
    ajax.start();
};
 
$(function () {
    Feng.initValidator("roleInfoForm", RolInfoDlg.validateFields);
 
    var deptTree = new $ZTree("deptTree", "/dept/tree");
    deptTree.bindOnClick(RolInfoDlg.onClickDept);
    deptTree.bindOnDblClick(RolInfoDlg.onDblClickDept)
    deptTree.init();
    RolInfoDlg.deptZtree = deptTree;
 
    var pNameTree = new $ZTree("pNameTree", "/role/roleTreeList");
    pNameTree.bindOnClick(RolInfoDlg.onClickPName);
    pNameTree.init();
    RolInfoDlg.pNameZtree = pNameTree;
});