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
/**
 * 初始化字典详情对话框
 */
var DictInfoDlg = {
    count: $("#itemSize").val(),
    dictName: '',            //字典的名称
    dictCode: '',//字典类型编码
    dictTips: '',//字典备注
    mutiString: '',        //拼接字符串内容(拼接字典条目)
    itemTemplate: $("#itemTemplate").html()
};
var language =$("#language").val()
/**
 * item获取新的id
 */
DictInfoDlg.newId = function () {
    if(this.count == undefined){
        this.count = 0;
    }
    this.count = this.count + 1;
    return "dictItem" + this.count;
};
 
/**
 * 关闭此对话框
 */
DictInfoDlg.close = function () {
    parent.layer.close(window.parent.Dict.layerIndex);
};
 
/**
 * 添加条目
 */
DictInfoDlg.addItem = function () {
    $("#itemsArea").append(this.itemTemplate);
    $("#dictItem").attr("id", this.newId());
};
 
/**
 * 删除item
 */
DictInfoDlg.deleteItem = function (event) {
    var obj = Feng.eventParseObject(event);
    obj = obj.is('button') ? obj : obj.parent();
    obj.parent().parent().remove();
};
 
/**
 * 清除为空的item Dom
 */
DictInfoDlg.clearNullDom = function(){
    $("[name='dictItem']").each(function(){
        var num = $(this).find("[name='itemNum']").val();
        var name = $(this).find("[name='itemName']").val();
        if(num == '' || name == ''){
            $(this).remove();
        }
    });
};
 
/**
 * 收集添加字典的数据
 */
DictInfoDlg.collectData = function () {
    this.clearNullDom();
    var mutiString = "";
    $("[name='dictItem']").each(function(){
        var code = $(this).find("[name='itemCode']").val();
        var name = $(this).find("[name='itemName']").val();
        var num = $(this).find("[name='itemNum']").val();
        mutiString = mutiString + (code + ":" + name + ":"+ num+";");
    });
    this.dictName = $("#dictName").val();
    this.dictCode = $("#dictCode").val();
    this.dictTips = $("#dictTips").val();
    this.mutiString = mutiString;
};
 
 
/**
 * 提交添加字典
 */
DictInfoDlg.addSubmit = function () {
    this.collectData();
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/dict/add", function (data) {
          if(language==1){
            Feng.success("添加成功!");
        }else if(language==2){
            Feng.success("Successfully added!");
        }else {
            Feng.success("Sangat berhasil ditambah!");
        }
        window.parent.Dict.table.refresh();
        DictInfoDlg.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('dictName',this.dictName);
    ajax.set('dictCode',this.dictCode);
    ajax.set('dictTips',this.dictTips);
    ajax.set('dictValues',this.mutiString);
    ajax.start();
};
 
/**
 * 提交修改
 */
DictInfoDlg.editSubmit = function () {
    this.collectData();
    var ajax = new $ax(Feng.ctxPath + "/dict/update", function (data) {
        if(language==1){
            Feng.success("修改成功!");
        }else if(language==2){
            Feng.success("Modify successfully!");
        }else {
            Feng.success("Mengubah dengan sukses!");
        }
        window.parent.Dict.table.refresh();
        DictInfoDlg.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('dictId',$("#dictId").val());
    ajax.set('dictName',this.dictName);
    ajax.set('dictCode',this.dictCode);
    ajax.set('dictTips',this.dictTips);
    ajax.set('dictValues',this.mutiString);
    ajax.start();
};