1function FormTender() { 2 3 var self = this; 4 5 /** 6 * ÐÑеÑÐ¸ÐºÑ Ð´Ð»Ñ ÑоÑÐ¼Ñ 7 * @type {string} 8 */ 9 this.form = '.js-form'; 10 11 /** 12 * ÐоÑÑÑÐ¸ÐºÑ Ð´Ð»Ñ Ð¸Ð´ÐµÐ½ÑиÑикаÑии ÑоÑÐ¼Ñ 13 * @type {string} 14 */ 15 this.formPostFix = '-order'; 16 17 /** 18 * ÐаÑÑив Ñ Ð½Ð°Ð·Ð²Ð°Ð½Ð¸Ñми input'ов 19 * @type {Array} 20 */ 21 this.inputsName = ['name', 'secondName', 'phone', 'email', 'product', 'comment']; 22 23 /** 24 * ÐаÑÑив Ñ Ð½Ð°Ð·Ð²Ð°Ð½Ð¸Ñми textarea'ов 25 * @type {Array} 26 */ 27 this.textareasName = []; 28 29 /** 30 * Ðоле input Ñ ÑелеÑоном на коÑоÑое бÑÐ´ÐµÑ Ð½Ð°ÐºÐ»Ð°Ð´ÑваÑÑÑÑ Ð¼Ð°Ñка 31 * @type {string} 32 */ 33 this.inputName = 'phone'; 34 35 /** 36 * ÐаÑка Ð´Ð»Ñ ÑелеÑона 37 * @type {string} 38 */ 39 this.phoneMask = '+7 (999) 999-99-99'; 40 41 /** 42 * СообÑение на ÑлÑÑай, еÑли поле не заполнено (оÑибка пеÑвого ÑÑовнÑ) 43 * @type {string} 44 */ 45 this.errorLvl1 = "<span class='errorText'>Ðоле не заполнено</span>"; 46 47 /** 48 * ÐÑобÑажение оÑибки вÑоÑого ÑÑÐ¾Ð²Ð½Ñ Ð´Ð»Ñ input'ов 49 * (поÑледоваÑелÑноÑÑÑ Ð¾Ñибок должна бÑÑÑ ÑÐ°ÐºÐ°Ñ Ð¶Ðµ как Ñ input'ов) 50 * @type {Array} 51 */ 52 this.errorLvl2 = [ 53 "<span class='errorText'>ÐÐ¼Ñ Ð´Ð¾Ð»Ð¶Ð½Ð¾ ÑодеÑжаÑÑ ÑолÑко бÑквÑ</span>", 54 "", 55 "<span class='errorText'>Ðоле должно ÑодеÑжаÑÑ ÑолÑко ÑиÑÑÑ</span>", 56 "<span class='errorText'>ÐлекÑÑоннÑй адÑÐµÑ Ð²Ð²ÐµÐ´ÐµÐ½ не веÑно</span>" 57 ]; 58 59 /** 60 * ÐадпиÑÑ Ð¾ÑобÑажаеÑÑÑ Ð¿Ñи ÑÑпеÑной оÑпÑавки ÑоÑÐ¼Ñ 61 * @type {string} 62 */ 63 this.theEnd = "<span class='succes'>ÐаÑа заÑвка ÑÑпеÑно заÑегиÑÑÑиÑована! ÐаÑе конкÑÑÑное пÑедложение ÐÑ Ð¼Ð¾Ð¶ÐµÑе напÑавиÑÑ ÑполномоÑÐµÐ½Ð½Ð¾Ð¼Ñ Ð»Ð¸ÑÑ ÐР«ÐÐ ÐЦл, ÑÐºÐ°Ð·Ð°Ð½Ð½Ð¾Ð¼Ñ Ð² опиÑании ÑендеÑа.</span>"; 64 65 /** 66 * ÐлаÑÑ Ð½Ð° коÑоÑÑй повеÑÐµÐ½Ñ ÑекÑÑовÑе оÑибки 67 * @type {string} 68 */ 69 this.errorText = 'errorText'; 70 71 /** 72 * ÐлаÑÑ Ð½Ð° коÑоÑÑй повеÑÐµÐ½Ñ Ð¾Ñибки на input и textarea 73 * @type {string} 74 */ 75 this.error = 'error'; 76 77 /** 78 * ÐаÑÑÑойка true, еÑли еÑÑÑ Ð·Ð°Ð³ÑÑзка Ñайла 79 * @type {boolean} 80 */ 81 this.withFile = false; 82 83 /** 84 * ÐбÑÐµÐºÑ Ð·Ð°Ð³ÑÑзки 85 */ 86 this.uploader; 87 88 /** 89 * ÐÑовеÑка, ÑÑо еÑÑÑ Ñже загÑÑженнÑй Ñайл 90 * @type {boolean} 91 */ 92 this.fileFirst = false; 93 94 /** 95 * УникалÑнÑй иденÑиÑикаÑÐ¾Ñ Ð¾Ð±ÑекÑа загÑÑзки 96 * @type {string} 97 */ 98 this.idObjectUpload = 'modal'; 99 100 /** 101 * ÐÐ»ÐµÐ¼ÐµÐ½Ñ Ðº коÑоÑÐ¾Ð¼Ñ Ð¿ÑикÑеплÑеÑÑÑ Ð·Ð°Ð³ÑÑзка Ñайла 102 * @type {string} 103 */ 104 this.uploadItem = "input[name='files']"; 105 106 /** 107 * СпиÑок Ñайлов, коÑоÑÑе Ñже пÑикÑÐµÐ¿Ð»ÐµÐ½Ñ 108 * @type {string} 109 */ 110 this.uploadList = '.js-fileUploadList'; 111 112 /** 113 * ÐблаÑÑÑ ÐºÐ¾ÑоÑÐ°Ñ Ð¾ÑвеÑÐ°ÐµÑ Ð·Ð° ÑÐ°Ð¹Ð»Ñ 114 * @type {string} 115 */ 116 this.fileUploadArea = '.js-fileUploadArea'; 117 118 /** 119 * ÐлаÑÑ Ð´Ð»Ñ ÑÐ´Ð°Ð»ÐµÐ½Ð¸Ñ Ñайла 120 * @type {string} 121 */ 122 this.deleteFile = '.js-deleteFile'; 123 124 /** 125 * ÐниÑиализаÑÐ¸Ñ Ð²ÑÐµÑ ÑобÑÑий 126 */ 127 this.init = function () { 128 129 this.initForm(); 130 this.initFormEvent(); 131 this.initFocusEvent(); 132 }; 133 134 this.time = function () { 135 return parseInt(new Date().getTime()/1000); 136 }; 137 138 this.random = function () { 139 return Math.random(); 140 }; 141 142 this.initForm = function () { 143 144 $('input[name="' + this.inputName + '"]').mask(this.phoneMask); 145 146 if (self.withFile == true) { 147 self.intUploader(); 148 149 /** 150 * СобÑÑие на Ñдаление Ñайла 151 */ 152 $(document).on('click', this.deleteFile, function(e){
153 e.preventDefault(); 154 155 self.deleteFileAction(); 156 }); 157 } 158 }; 159 160 /** 161 * ÐниÑиализаÑÐ¸Ñ Ð·Ð°Ð³ÑÑзÑика 162 */ 163 this.intUploader = function () { 164 165 var uniqueId = 'browse' + this.time() + this.random(); 166 167 // ÐазнаÑаем id ÑлеменÑÑ Ð¸Ð· ÑоÑÐ¼Ñ 168 $(this.uploadItem).attr('id', uniqueId); 169 170 // ÐоÑом деÑгаем ÑÑÐ¾Ñ ÑÐ»ÐµÐ¼ÐµÐ½Ñ Ð¸Ð· DOM 171 var elem1 = document.getElementById(uniqueId); 172 173 var fileUrl = $(this.form + this.formPostFix).attr('data-file'); 174 175 // ÐодÑÑкаем 176 177 var id = this.idObjectUpload; 178 179 this.uploader = new plupload.Uploader({ 180 multipart_params: {id : id}, 181 browse_button: elem1, 182 url: fileUrl, 183 multi_selection: false, 184 filters: { 185 max_file_size: '5mb', 186 mime_types: [ 187 {title: "Image files", extensions: "jpg,gif,png,jpeg,doc,docx,xls,xlsx"} 188 ] 189 } 190 }); 191 192 this.uploader.init(); 193 194 /** 195 * Ðобавление Ñайла 196 */ 197 this.uploader.bind('FilesAdded', function(up, files) { 198 199 if (self.fileFirst == false) { 200 201 var html = ''; 202 203 plupload.each(files, function(file) { 204 html += '<span data-id="' + file.id + '">' + file.name + ' <a class="js-deleteFile" href="#">×</a></span>'; 205 }); 206 207 $(self.uploadList).append(html); 208 self.uploader.start(); 209 self.fileFirst = true; 210 } else { 211 var count = self.uploader.files.length; 212 var tmp = self.uploader.files; 213 214 for (var i = 0; i < count; i++) { 215 if (i != 0) { 216 self.uploader.removeFile(tmp[i]); 217 } 218 } 219 220 alert('ÐелÑÐ·Ñ Ð¿ÑикÑепиÑÑ Ðº заÑвке более одного Ñайла'); 221 } 222 }); 223 224 /** 225 * ÐÑоÑеÑÑ Ð·Ð°Ð³ÑÑзки 226 */ 227 this.uploader.bind('UploadProgress', function(up, file) { 228 229 if ($(self.fileUploadArea).hasClass(self.error)) { 230 $(self.fileUploadArea).removeClass(self.error); 231 $(self.fileUploadArea).next().remove(); 232 } 233 234 $(self.form + self.formPostFix).addClass('loading'); 235 }); 236 237 /** 238 * Файл загÑÑжен 239 */ 240 this.uploader.bind('FileUploaded', function(up, file, info) { 241 // Файл загÑÑжен 242 var response = JSON.parse(info.response); 243 $(self.form + self.formPostFix).removeClass('loading'); 244 245 if (response.data.error == 'maxSizeFile') { 246 self.resetErrorClass($(self.fileUploadArea)); 247 248 $(self.uploadList).empty(); 249 self.uploader.removeFile(self.uploader.files[0]); 250 $(self.form + self.formPostFix + " " + self.fileUploadArea).after("<span class='errorText'>Файл ÑлиÑком болÑÑой (Ñайл не должен бÑÑÑ Ð±Ð¾Ð»ÑÑе 5 Ðб)</span>"); 251 } 252 253 if (response.data.error == 'noAvaliable') { 254 self.resetErrorClass($(self.fileUploadArea)); 255 256 $(self.uploadList).empty(); 257 self.uploader.removeFile(self.uploader.files[0]); 258 $(self.form + self.formPostFix + " " + self.fileUploadArea).after("<span class='errorText'>Файл Ð¸Ð¼ÐµÐµÑ Ð½Ðµ допÑÑÑимое ÑаÑÑиÑение (допÑÑÑÐ¸Ð¼Ñ ÑаÑÑиÑениÑ: jpg,gif,png,jpeg,doc,docx,xls,xlsx)</span>"); 259 } 260 }); 261 262 this.uploader.bind('Error', function(up, err) { 263 if (err.code == -601) { 264 self.resetErrorClass($(self.fileUploadArea)); 265 266 $(self.form + self.formPostFix + " " + self.fileUploadArea).addClass(self.error); 267 $(self.uploadList).empty(); 268 $(self.form + self.formPostFix + " " + self.fileUploadArea).after("<span class='errorText'>Файл Ñакого ÑаÑÑиÑÐµÐ½Ð¸Ñ Ð¸Ð»Ð¸ Ñакого ÑазмеÑа загÑÑжаÑÑ Ð½ÐµÐ»ÑзÑ</span>"); 269 } 270 }); 271 }; 272 273 /** 274 * Удаление Ñайла на ÑеÑвеÑе 275 * @returns {boolean} 276 */ 277 this.deleteFileAction = function () { 278 279 var deleteFileUrl = $(this.form + this.formPostFix).attr('data-deleteFile'); 280 281 if (deleteFileUrl == undefined) { 282 return false; 283 } 284 285 if (self.fileFirst == true) { 286 287 $.ajax({
288 type: "POST", 289 url: deleteFileUrl, 290 success: function(response) 291 { 292 if (response.status.code != 1001) { 293 if (response.data.succes === 'Ok') { 294 if (self.fileFirst == true) { 295 296 $(self.uploadList).empty(); 297 298 self.uploader.removeFile(self.uploader.files[0]); 299 self.fileFirst = false; 300 } 301 } 302 } 303 } 304 }); // $.ajax 305 } 306 }; 307 308 /** 309 * Удаление оÑибок на input'Ð°Ñ 310 */ 311 this.resetInputError = function () { 312 313 this.inputsName.forEach(function(item, i) { 314 315 var $object = $(self.form + self.formPostFix + " input[name='" + item + "']"); 316 self.resetErrorClass($object); 317 }); 318 319 if (self.withFile == true) { 320 321 var $object = $(self.fileUploadArea); 322 self.resetErrorClass($object); 323 324 self.deleteFileAction(); 325 } 326 }; 327 328 /** 329 * Удаление оÑибок на input'Ð°Ñ 330 */ 331 this.resetTextAreaError = function () { 332 333 this.textareasName.forEach(function(item, i) { 334 335 var $object = $(self.form + self.formPostFix + " textarea[name='" + item + "']"); 336 337 self.resetErrorClass($object); 338 }); 339 }; 340 341 /** 342 * Удаление подÑвеÑÐ¸Ð²Ð°Ð½Ð¸Ñ ÑлеменÑа и подпиÑи под ним 343 * @param $object 344 */ 345 this.resetErrorClass = function ($object) { 346 347 if ($object.hasClass('error')) { 348 349 $object.removeClass('error'); 350 $object.next().remove(); 351 } 352 }; 353 354 /** 355 * ÐбÑабоÑка ÑобÑÑÐ¸Ñ Ð¾ÑпÑавки ÑоÑÐ¼Ñ 356 */ 357 this.initFormEvent = function () { 358 359 $(document).on('submit', self.form + self.formPostFix, function(e){ 360 e.stopPropagation(); 361 e.preventDefault(); 362 363 var vars = $(this).serialize(); 364 var furl = $(this).attr('action'); 365 366 //if (typeof yaCounter46377009 != 'undefined') { 367 368 yaCounter46377009.reachGoal('submit_form_tender'); 369 370 // } 371 372 $.ajax({
373 type: "POST", 374 url: furl, 375 data: vars, 376 success: function(response) 377 { 378 if (response.status.code != 1001) { 379 380 if (response.data.succes === 'Ok') { 381 382 self.theEndText(response.data); 383 } 384 } else { 385 386 if (response.data.honeyPot != undefined) { 387 return; 388 } 389 390 // ÑнÑÑÑ Ð²ÐµÐ·Ð´Ðµ клаÑÑ Ð¾Ñибки 391 self.inputsName.forEach(function(item, i) { 392 $(self.form + self.formPostFix + " input[name='" + item + "']").removeClass(self.error); 393 }); 394 395 self.textareasName.forEach(function(item, i) { 396 $(self.form + self.formPostFix + " textarea[name='" + item + "']").removeClass(self.error); 397 }); 398 399 $(self.form + self.formPostFix + " span[class='" + self.errorText + "']").remove(); 400 401 // ÐÑовеÑка на оÑибки пеÑвого ÑÑÐ¾Ð²Ð½Ñ Ñ input'ов 402 self.inputsName.forEach(function(item, i) { 403 $(self.form + self.formPostFix + " input[name='" + item + "']").removeClass(self.error); 404 405 if (response.data.error[item] != 'undefined') { 406 407 if (response.data.error[item] == item + '!') { 408 409 $(self.form + self.formPostFix + " input[name='" + item + "']").addClass(self.error); 410 $(self.form + self.formPostFix + " input[name='" + item + "']").after(self.errorLvl1); 411 } 412 413 if (response.data.error[item] == item + '!!') { 414 415 $(self.form + self.formPostFix + " input[name='" + item + "']").addClass(self.error); 416 $(self.form + self.formPostFix + " input[name='" + item + "']").after(self.errorLvl2[i]); 417 } 418 } 419 }); 420 421 // ÐÑовеÑка на оÑибки пеÑвого ÑÑÐ¾Ð²Ð½Ñ Ñ textarea 422 self.textareasName.forEach(function(item, i) { 423 424 $(self.form + self.formPostFix + " textarea[name='" + item + "']").removeClass(self.error); 425 426 if (response.data.error[item] != 'undefined') { 427 428 if (response.data.error[item] == item + '!') { 429 430 $(self.form + self.formPostFix + " textarea[name='" + item + "']").addClass(self.error); 431 $(self.form + self.formPostFix + " textarea[name='" + item + "']").after(self.errorLvl1); 432 } 433 434 if (response.data.error[item] == item + '!!') { 435 436 $(self.form + self.formPostFix + " textarea[name='" + item + "']").addClass(self.error); 437 $(self.form + self.formPostFix + " textarea[name='" + item + "']").after(self.errorLvl2[i]); 438 } 439 } 440 }); 441 } 442 } 443 }); // $.ajax 444 }); 445 }; 446 447 /** 448 * ÐаÑÑомнÑе дейÑÑÐ²Ð¸Ñ Ð¿Ñи ÑÑпеÑной оÑпÑавки ÑоÑÐ¼Ñ 449 */ 450 this.theEndText = function (data) { 451 452 $(self.form + self.formPostFix).empty(); 453 $(self.form + self.formPostFix).append(self.theEnd); 454 }; 455 456 this.initFocusEvent = function () { 457 458 this.inputsName.forEach(function(item, i) { 459 460 $(document).on('focus', self.form + self.formPostFix + " input[name='" + item + "']", function(e) { 461 462 if ($(this).hasClass('error')) { 463 464 $(this).removeClass('error'); 465 $(this).next().remove(); 466 } 467 }); 468 }); 469 470 this.textareasName.forEach(function(item, i) { 471 472 $(document).on('focus', self.form + self.formPostFix + " textarea[name='" + item + "']", function(e) { 473 474 if ($(this).hasClass('error')) { 475 476 $(this).removeClass('error'); 477 $(this).next().remove(); 478 } 479 }); 480 }); 481 }; 482}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.