buli
2022-03-11 93e56e36ad8a653d2a463e757503d8b896cc0382
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
/*
 * 备品借出申请
 */
(function(win) {
    //*******************************************************************************************************
    // パラメータ
    //*******************************************************************************************************
    TEXT_AREA_ID = "00N10000003MspG";
    LOCAL_HREF = document.location.href;
    SPLIT_ROW = "\n";
    SPLIT_COL1 = ",";
    SPLIT_COL2 = "(";
    SPLIT_COL3 = ")";
  
    //*******************************************************************************************************
    // textareaをtableに変換
    //*******************************************************************************************************
    win._sfMakeTextAreaTable = function() {
        var ins = document.getElementById(TEXT_AREA_ID);
        var insVal = ins.value;
        var tbl = document.createElement("table");
        
        // ヘッダ作成
        var th1 = document.createElement("th");th1.style.width="150px";
        var th2 = document.createElement("th");th2.style.width="30px";
        var th3 = document.createElement("th");th3.style.width="150px";
        th1.innerHTML = "型式";
        th2.innerHTML = "数量";
        th3.innerHTML = "备注";
        tbl.appendChild(th1);
        tbl.appendChild(th2);
        tbl.appendChild(th3);
        
        var tr;
        var td;
        
        if (insVal != "") {
            var rows = insVal.split(SPLIT_ROW);
            for (var i = 0; i < rows.length; i++) {
                tr = document.createElement("tr");
 
                var idx1 = rows[i].indexOf(SPLIT_COL1);
                if (idx1 > 0) {
                    var col1 = rows[i].substring(0, idx1);
                    var col2 = rows[i].substring(idx1 + 1);
                    
                    td = document.createElement("td");
                    td.innerHTML = "<input type='text' style='width:95%;' value='" + col1 + "' onchange='_sfMakeTextAreaStr();' />";
                    tr.appendChild(td);
                    
                    var cols = col2.split(SPLIT_COL2);
                    td = document.createElement("td");
                    td.innerHTML = "<input type='text' style='width:95%;' value='" + cols[0] + "' onchange='_sfMakeTextAreaStr();' />";
                    tr.appendChild(td);
                    
                    if (cols.length > 1) {
                        td = document.createElement("td");
                        td.innerHTML = "<input type='text' style='width:95%;' value='" + cols[1].substring(0, cols[1].length - 1) + "' onchange='_sfMakeTextAreaStr();' />";
                        tr.appendChild(td);
                    } else {
                        td = document.createElement("td");
                        td.innerHTML = "<input type='text' value='' onchange='_sfMakeTextAreaStr();' />";
                        tr.appendChild(td);
                    }
                } else {
                    td = document.createElement("td");
                    td.innerHTML = "<input type='text' value='" + rows[i] + "' onchange='_sfMakeTextAreaStr();' />";
                    tr.appendChild(td);
                    
                    td = document.createElement("td");
                    td.innerHTML = "<input type='text' value='' onchange='_sfMakeTextAreaStr();' />";
                    tr.appendChild(td);
                    
                    td = document.createElement("td");
                    td.innerHTML = "<input type='text' value='' onchange='_sfMakeTextAreaStr();' />";
                    tr.appendChild(td);
                }
                
                tbl.appendChild(tr);
            }
        }
        
        // 後ろ常に五行追加
        for (var i = 0; i < 5; i++) {
            tr = document.createElement("tr");
            for (var j = 0; j < 3; j++) {
                td = document.createElement("td");
                td.innerHTML = "<input type='text' style='width:95%;' value='' onchange='_sfMakeTextAreaStr();' />";
                tr.appendChild(td);
            }
            tbl.appendChild(tr);
        }
        
        tbl.id = ins.id+"_new";
        tbl.name = ins.name;
        var insertedNode = ins.parentNode.insertBefore(tbl, ins);
        ins.style.display="none";
        
        // インラインDialogの場合
        var origEnter = sfdcPage.getDialogById('InlineEditDialog').enter;
        var origCancel = sfdcPage.getDialogById('InlineEditDialog').cancel;
        var inlineEnter = function() {
            sfdcPage.getDialogById('InlineEditDialog').enter = origEnter;
            sfdcPage.getDialogById('InlineEditDialog').cancel = origCancel;
            _sfMakeTextAreaStr();
            if (sfdcPage.getInlineEditData().closeCurrentField()) {
                sfdcPage.getDialogById("InlineEditDialog").hide();
            }
            ins.style.display="block";
            ins.parentNode.removeChild(insertedNode);
        }
        var inlineCancel = function() {
            sfdcPage.getDialogById('InlineEditDialog').enter = origEnter;
            sfdcPage.getDialogById('InlineEditDialog').cancel = origCancel;
            ins.value = insVal;
            if (sfdcPage.getInlineEditData().closeCurrentField()) {
                sfdcPage.getDialogById("InlineEditDialog").hide();
            }
            ins.style.display="block";
            ins.parentNode.removeChild(insertedNode);
        }
        sfdcPage.getDialogById('InlineEditDialog').enter = inlineEnter;
        sfdcPage.getDialogById('InlineEditDialog').cancel = inlineCancel;
 
        // インラインDialogの場合、OKとキャンセルボタンがあります。
        var e = document.getElementById("InlineEditDialog_buttons");
        if (e) {
            if (e = e.firstChild) {
                e.setAttribute("onclick", "sfdcPage.getDialogById('InlineEditDialog').enter();");
            }
            if (e = e.nextSibling) {
                e.setAttribute("onclick", "sfdcPage.getDialogById('InlineEditDialog').cancel();");
            }
        }
    }
 
    //*******************************************************************************************************
    // tableの値をtextareaに書き戻す
    //*******************************************************************************************************
    win._sfMakeTextAreaStr = function() {
        var tbl = document.getElementById(TEXT_AREA_ID + "_new");
        var trs = tbl.getElementsByTagName('tr');
        var finalStr = "";
        for (var i = 0; i < trs.length; i++) {
            for (var j = 0; j < trs[i].cells.length; j++) {
                var cell = trs[i].cells[j];
                var cellVal = cell.childNodes[0].value;
                
                if (j == 0) {
                    if (cellVal == "") break;;
                    finalStr += cellVal;
                }
                if (j == 1) {
                    if (cellVal == "") cellVal = 0;
                    finalStr += SPLIT_COL1 + cellVal;
                }
                if (j == 2) {
                    if (cellVal == "") {
                        finalStr += SPLIT_ROW;
                    } else {
                        finalStr += SPLIT_COL2 + cellVal + SPLIT_COL3 + SPLIT_ROW;
                    }
                }
            }
        }
        // trim
        finalStr = finalStr.replace(/(^\s+)|(\s+$)/g, "");
        // テキストエリア項目に書き戻す
        document.getElementById(TEXT_AREA_ID).value = finalStr;
    }
    
    //*******************************************************************************************************
    // 初期処理
    //*******************************************************************************************************
    var run = function() {
        if (LOCAL_HREF.match(/\/e/)) {
            _sfMakeTextAreaTable();
        } else {
            // インライン編集の対応
            var originalEvent = document.getElementById(TEXT_AREA_ID + "_ilecell");
            if (originalEvent) {
                addEvent(originalEvent, "dblclick", function(elems) {
                    return function(deepDataAndEvents) {
                        if (win.sfdcPage) {
                            if (win.sfdcPage.hasRun) {
                                sfdcPage.dblClickField(deepDataAndEvents, elems);
                                setTimeout("_sfMakeTextAreaTable()", 500);
                            }
                        }
                    };
                }(originalEvent));
                addEvent(originalEvent, "keypress", function(elems) {
                    return function(e) {
                        if (win.sfdcPage) {
                            if (win.sfdcPage.hasRun && (e && e.keyCode == KEY_ENTER)) {
                                sfdcPage.dblClickField(e, elems);
                                setTimeout("_sfMakeTextAreaTable()", 500);
                            }
                        }
                    };
                }(originalEvent));
            }
        }
    }
    if (win.sfdcPage) {
        sfdcPage.appendToOnloadQueue(function() {
            if (LOCAL_HREF.match(/\/a0t/)) {
                run();
            }
        });
    }
})(window);