cla.js 9.4 KB
Newer Older
E
edisonxiang 已提交
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
$(function () {
    initClaPage();
    initCurrentDate();
})

function initCurrentDate() {
    var now = new Date();
    var year = now.getFullYear();
    var month = now.getMonth();
    var date = now.getDate();
    month = month + 1;

    if (month < 10) month = "0" + month;
    if (date < 10) date = "0" + date;

    time = year + "-" + month + "-" + date;

    if ($('#individual-table').length) {
        $('#individual-date').val(time);
        $('#individual-date').attr("disabled", true);
    }
    if ($('#legalentity-table').length) {
        $('#legalentity-date').val(time);
        $('#legalentity-date').attr("disabled", true);
    }
}

// init cla page
function initClaPage() {
    if ($('#cla-type-table').length) {
        $('td', '#cla-type-table').click(function () {
            // select checked
            $('input[name="track"]').removeAttr('checked');
            $(this).find('input[name="cla-type-radio"]').prop('checked', true);

            // show or hide
            v = $('input[name="cla-type-radio"]:checked').val();
            if (v == 0) {
                $('#individual-table').show();
                $('#legalentity-table').hide();
            } else {
                $('#individual-table').hide();
                $('#legalentity-table').show();
            }
        });
    }

    if ($('#sign-cla-button').length) {
        $("#sign-cla-button").bind('click', function () {
E
edisonxiang 已提交
50
            v = parseInt($('input[name="cla-type-radio"]:checked').val());
E
edisonxiang 已提交
51 52 53 54 55 56 57 58 59 60 61
            var regphone = /^(\d{4}-|\d{3}-)?(\d{8}|\d{7})$/;
            var regmobile = /^1\d{10}$/;
            var regemail = /^[-_A-Za-z0-9]+@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$/;
            $('#tip-cla-label').html('');
            lang = $('html').attr('lang');

            if (v == 0) {
                // individual
                var checkpass = true;
                $("input[type=text]", "#individual-table").each(function (i) {
                    if ($(this).hasClass("require")) {
E
edisonxiang 已提交
62
                        if ($.trim($(this).val()) == "") {
E
edisonxiang 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76
                            checkpass = false;
                            return false;
                        }
                    }
                    return true;
                });
                if (!checkpass) {
                    if (lang == "zh-cn") {
                        $('#tip-cla-label').html("必填字段缺失!");
                    } else {
                        $('#tip-cla-label').html("Required field is missing!");
                    }
                    return false;
                }
E
edisonxiang 已提交
77
                var email = $.trim($('#individual-email').val());
E
edisonxiang 已提交
78 79 80 81 82 83 84 85
                if (!regemail.test(email)) {
                    if (lang == "zh-cn") {
                        $('#tip-cla-label').html("邮箱格式不正确!");
                    } else {
                        $('#tip-cla-label').html("E-Mail format is incorrent!");
                    }
                    return false;
                }
E
edisonxiang 已提交
86
                var telephone = $.trim($('#individual-telephone').val());
E
edisonxiang 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99
                if ((!regphone.test(telephone)) && (!regmobile.test(telephone))) {
                    if (lang == "zh-cn") {
                        $('#tip-cla-label').html("电话格式不正确!");
                    } else {
                        $('#tip-cla-label').html("Telephone format is incorrent!");
                    }
                    return false;
                }
            } else {
                // legalentity
                var checkpass = true;
                $("input[type=text]", "#legalentity-table").each(function (i) {
                    if ($(this).hasClass("require")) {
E
edisonxiang 已提交
100
                        if ($.trim($(this).val()) == "") {
E
edisonxiang 已提交
101 102 103 104 105 106 107 108 109 110 111 112 113 114
                            checkpass = false;
                            return false;
                        }
                    }
                    return true;
                });
                if (!checkpass) {
                    if (lang == "zh-cn") {
                        $('#tip-cla-label').html("必填字段缺失!");
                    } else {
                        $('#tip-cla-label').html("Required field is missing!");
                    }
                    return false;
                }
E
edisonxiang 已提交
115
                var email = $.trim($('#legalentity-email').val());
E
edisonxiang 已提交
116 117 118 119 120 121 122 123
                if (!regemail.test(email)) {
                    if (lang == "zh-cn") {
                        $('#tip-cla-label').html("邮箱格式不正确!");
                    } else {
                        $('#tip-cla-label').html("E-Mail format is incorrent!");
                    }
                    return false;
                }
E
edisonxiang 已提交
124
                var telephone = $.trim($('#legalentity-telephone').val());
E
edisonxiang 已提交
125 126 127 128 129 130
                if ((!regphone.test(telephone)) && (!regmobile.test(telephone))) {
                    if (lang == "zh-cn") {
                        $('#tip-cla-label').html("电话格式不正确!");
                    } else {
                        $('#tip-cla-label').html("Telephone format is incorrent!");
                    }
E
edisonxiang 已提交
131
                    return false;
E
edisonxiang 已提交
132 133 134
                }
            }

E
edisonxiang 已提交
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
            // build json
            var posturl = $(this).attr("posturl");
            var jsonData = {};
            if (v == 0) {
                // individual
                jsonData = {
                    "type": v,
                    "name": $.trim($('#individual-name').val()),
                    "address": $.trim($('#individual-address').val()),
                    "date": $.trim($('#individual-date').val()),
                    "email": $.trim($('#individual-email').val()),
                    "telephone": $.trim($('#individual-telephone').val()),
                    "fax": $.trim($('#individual-fax').val()),
                };
            } else {
                // legalentity
                jsonData = {
                    "type": v,
                    "name": $.trim($('#legalentity-name').val()),
                    // only for legalentity
                    "title": $.trim($('#legalentity-title').val()),
                    // only for legalentity
                    "corporation": $.trim($('#legalentity-corporation').val()),
                    "address": $.trim($('#legalentity-address').val()),
                    "date": $.trim($('#legalentity-date').val()),
                    "email": $.trim($('#legalentity-email').val()),
                    "telephone": $.trim($('#legalentity-telephone').val()),
                    "fax": $.trim($('#legalentity-fax').val()),
                };
            }

            // send request
            $.ajax({
                type: "POST",
                url: posturl,
                data: JSON.stringify(jsonData),
                contentType: "application/json; charset=utf-8",
                crossDomain: true,
                datatype: "json",
                success: function (data) {
E
edisonxiang 已提交
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
                    if (data) {
                        if(data.isSuccess) {
                            $("#reset-cla-button").trigger('click');
                            if (lang == "zh-cn") {
                                alert("签署成功!");
                            } else {
                                alert("Sign succeed!");
                            }
                        } else {
                            if(data.errorCode == 1) {
                                if (lang == "zh-cn") {
                                    alert("服务器处理错误!");
                                } else {
                                    alert("Server handle error!");
                                }
                            } else if (data.errorCode == 2) {
                                if (lang == "zh-cn") {
                                    alert("邮箱已经被注册!");
                                } else {
                                    alert("E-Mail is already registered!");
                                }
                            } else if (data.errorCode == 3) {
                                if (lang == "zh-cn") {
                                    alert("电话已经被注册!");
                                } else {
                                    alert("Telephone is already registered!");
                                }  
                            }
                        }
                    }
                    else {
                        if (lang == "zh-cn") {
                            alert("签署失败!");
                        } else {
                            alert("Sign failed!");
                        }
                    }
E
edisonxiang 已提交
212 213
                },
                error: function () {
E
edisonxiang 已提交
214 215 216 217 218
                    if (lang == "zh-cn") {
                        alert("签署失败!");
                    } else {
                        alert("Sign failed!");
                    }
E
edisonxiang 已提交
219 220 221
                }
            });

E
edisonxiang 已提交
222 223 224 225 226 227 228 229 230 231 232 233 234 235
            return false;
        });
    }

    if ($('#reset-cla-button').length) {
        $("#reset-cla-button").bind('click', function () {
            $('input[type="text"]', '#individual-table').val('');
            $('input[type="text"]', '#legalentity-table').val('');
            $('#tip-cla-label').html('');
            initCurrentDate();
            return false;
        });
    }
}