涂煌豪
2022-03-18 fbf3ce2885477fd0dfbd8ec6b490636dc0f680dc
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
241
242
243
244
245
246
247
function keyCheck(keyCodes, num, str){
    if(keyCodes == 46 || keyCodes == 8 || keyCodes == 37 || keyCodes == 39 || keyCodes == 9){
        return true;
    }
    else if(str.value.length < num && ((keyCodes >= 48 && keyCodes <= 57) || (keyCodes >= 95 && keyCodes <= 105))){
        return true;
    }
    else{
        return false;
    }
}
function keyCheckAmount(keyCodes, num, str){
    if(keyCodes == 46 || keyCodes == 8 || keyCodes == 37 || keyCodes == 39 || keyCodes == 9){
        return true;
    }
    else if(str.value.length < num && ((keyCodes >= 48 && keyCodes <= 57) || (keyCodes >= 95 && keyCodes <= 105) || keyCodes == 110 || keyCodes == 190)){
        return true;
    }
    else{
        return false;
    }
}
function onKeyEvent(e) {
    e = e || window.event;
    if(e.keyCode == 13){ //Enter キー
        return false;   //無効
    }
    return true;
}
 
function escapeVfId(vfId) {
    return '#' + vfId.replace(/(:|\.)/g,'\\$1');
}
 
//function escapeURI(pOrg) {
//    var rtn = pOrg
//    rtn = rtn.split("!").join("%21");
//    rtn = rtn.split("#").join("%23");
//    rtn = rtn.split("$").join("%24");
//    rtn = rtn.split("%").join("%25");
//    rtn = rtn.split("'").join("%27");
//    rtn = rtn.split("(").join("%28");
//    rtn = rtn.split(")").join("%29");
//    rtn = rtn.split("*").join("%2A");
//    rtn = rtn.split("+").join("%2B");
//    rtn = rtn.split(",").join("%2C");
//    rtn = rtn.split("-").join("%2D");
//    rtn = rtn.split(".").join("%2E");
//    rtn = rtn.split("/").join("%2F");
//    rtn = rtn.split(":").join("%3A");
//    rtn = rtn.split(";").join("%3B");
//    rtn = rtn.split("=").join("%3D");
//    rtn = rtn.split("?").join("%3F");
//    rtn = rtn.split("@").join("%40");
//    rtn = rtn.split("_").join("%5F");
//    rtn = rtn.split("~").join("%7E");
//    rtn = rtn.split(" ").join("+");
//    return rtn;
//}
 
function isArray(o){
    return o != null && typeof o === "object" && 'pop' in o && 'join' in o;
}
 
function scrollbarWidth() {
    var $inner = jQuery('<div style="width: 100%; height:200px;">test</div>'),
        $outer = jQuery('<div style="width:200px;height:150px; position: absolute; top: 0; left: 0; visibility: hidden; overflow:hidden;"></div>').append($inner),
        inner = $inner[0],
        outer = $outer[0];
     
    jQuery('body').append(outer);
    var width1 = inner.offsetWidth;
    $outer.css('overflow', 'scroll');
    var width2 = outer.clientWidth;
    $outer.remove();
 
    return (width1 - width2);
}
 
function setButtonDisable(object, status){
    if(!(object.id == 'idGetActive' || object.id == 'Page:mainForm:idDayEdit:idReportDate')) {
        object.disabled = status;
    }
    if(object.id != 'idGetActive' && object.tagName.toLowerCase() == "input" && (object.type.toLowerCase() == "button" || object.type.toLowerCase() == "submit")) {
        if(status == true) {
            object.style.cursor = "default";
            object.style.backgroundPosition = "0 -90px";
            object.style.borderColor = "#C4C4C4";
            object.style.color = "#909090";
            
        } else {
            object.style.backgroundPosition = "";
            object.style.color = "";
            object.style.cursor = "pointer";
            object.style.borderColor = "#B5B5B5 #B5B5B5 #7F7F7F";
        }
    }
}
 
function setButtonsDisable(jObj, status){
    jObj.each(function(index) {
        setButtonDisable(this, status);
    });
}
 
function number_format_common (number, decimals, dec_point, thousands_sep) {
  number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
  var n = !isFinite(+number) ? 0 : +number,
    prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
    sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
    dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
    s = '',
    toFixedFix = function (n, prec) {
      var k = Math.pow(10, prec);
      return '' + Math.round(n * k) / k;
    };
  // Fix for IE parseFloat(0.55).toFixed(0) = 0;
  s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
  if (s[0].length > 3) {
    s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
  }
  if ((s[1] || '').length < prec) {
    s[1] = s[1] || '';
    s[1] += new Array(prec - s[1].length + 1).join('0');
  }
  return ( s.join(dec));
}
 
function toNum( input) {
    return number_format_common( input, 2, ".", "");
}
 
function toNumComma( input) {
    return number_format_common( input, 2, ".", ",");
}
 
function localParseFloat( input) {
    input += "";
    input = input.split(" ");
    if (input.length > 1) {
        input = input[1];
    } else {
        input = input[0];
    }
    input = input.replace(/,/g, "");
    input = input.replace(/ /g, "");
    if ( input == '' || isNaN( input)) {
        input = 0.00;
    }
    input = parseFloat(input);
    return input;
}
function localParseInt( input) {
    input += "";
    input = input.split(" ");
    if (input.length > 1) {
        input = input[1];
    } else {
        input = input[0];
    }
    input = input.replace(/,/g, "");
    input = input.replace(/ /g, "");
    if ( input == '' || isNaN( input)) {
        input = 0;
    }
    input = parseInt(input);
    return input;
}
 
function SFDCAddRemote(sessionId) {
    var binding = new XMLHttpRequest();
    var request = 
        '<?xml version="1.0" encoding="utf-8"?>' + 
        '<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'+
            '<env:Header>' + 
                '<urn:SessionHeader xmlns:urn="http://soap.sforce.com/2006/04/metadata">' + 
                    '<urn:sessionId>'+sessionId+'</urn:sessionId>' + 
                '</urn:SessionHeader>' + 
            '</env:Header>' + 
            '<env:Body>' +
                '<createMetadata xmlns="http://soap.sforce.com/2006/04/metadata">' + 
                    '<metadata xsi:type="RemoteSiteSetting">' + 
                        '<fullName>SoapApi_'+window.location.hostname.split('.')[1]+'</fullName>' + 
                        '<description>for Metadata API</description>' + 
                        '<disableProtocolSecurity>false</disableProtocolSecurity>' + 
                        '<isActive>true</isActive>' + 
                        '<url>https://' + window.location.hostname + '</url>' +
                    '</metadata>' +
                '</createMetadata>' +
            '</env:Body>' + 
        '</env:Envelope>';
    binding.open('POST', 'https://' + window.location.hostname + '/services/Soap/m/31.0');
    binding.setRequestHeader('SOAPAction','""');
    binding.setRequestHeader('Content-Type', 'text/xml');
    binding.onreadystatechange = 
        function() { 
            if(this.readyState==4 && this.status == 200) {
                var parser = new DOMParser();
                var doc  = parser.parseFromString(this.response, 'application/xml');
                var errors = doc.getElementsByTagName('errors');
                if (errors != null && errors.length > 0) {
                    var messageText = '';
                    for(var errorIdx = 0; errorIdx < errors.length; errorIdx++)
                        messageText+= errors.item(errorIdx).getElementsByTagName('message').item(0).innerHTML + '\n';
                    alert("Error:"+messageText);
                } else {
                    alert("Remote Site Added! Please Refresh!");
                }
            }
        }
    binding.send(request);
}
 
//TODO javascript DML メッセージ表示用のところ全部変更する必要がります。ここはあってます
var getConnectDMLErrorMessages = function (results) {
    var messages = [],
        i = 0,
        len = results.length,
        r;
    for (; i < len; i++) {
        r = results[i];
        if (! r.getBoolean("success")) {
            messages = messages.concat(getConnectDMLMessagesOfAResult(r));
        }
    }
    return messages;
};
var getConnectDMLMessagesOfAResult = function (res) {
    var messages = [],
        errors = res.getArray("errors"),
        i = 0,
        len = errors.length,
        e;
    for (; i < len; i++) {
        e = errors[i];
        messages.push(e.message + "  " + getConnectDMLErrorFields(e));
    }
    return messages;
};
var getConnectDMLErrorFields = function (error) {
    var fields = error.getArray('fields');
    if (fields.length > 0) {
        return "[" + fields.join(",") + "]"
    } else {
        return "";
    }
};