Blame view

js/OrderContol.js 17.6 KB
84f56040   andryeyev   + Редактирование ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  // ==================
  // ==== function ====
  // ==================
  
      // ===============
      // ==== ÎÁÙÅÅ ====  
      // ===============
  
      function getUrlVars (name) 
      {  
  	    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  	    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
  	        results = regex.exec(location.search);
  	    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); 
      } 
42868d70   andryeyev   Создал GIT
16
      
84f56040   andryeyev   + Редактирование ...
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
      function RemoveDiv(div) 
      { 
          if(typeof div== 'string') div=document.getElementById(div);
          if(div && div.parentNode)div.parentNode.removeChild(div);
          SumPerRow();
  
          return false;
      }
      
      function notify(url)
      {
          if (confirm("Âûñëàòü óâåäîìëåíèå?"))
          {
              document.location = url;
              return true;
          }
          return false;
      }
      
      function empty (mixed_var) {
          if (mixed_var === "" || mixed_var === 0 || mixed_var === "0" || mixed_var === null || mixed_var === false || typeof mixed_var === 'undefined') {
              return true;
          }
      }
42868d70   andryeyev   Создал GIT
41
      
84f56040   andryeyev   + Редактирование ...
42
43
44
45
46
47
48
49
50
51
52
53
54
      function isset(id) {  
  
          if((document) && (document.getElementById(id))) {
              return true;
          } else { 
              return false;
          }
  
      }
  
      // ===============
      // ==== ÇÀÊÀÇ ====  
      // ===============
42868d70   andryeyev   Создал GIT
55
      
c52bd933   andryeyev   - удаление модифи...
56
57
58
59
60
61
62
63
      var c = 0;
      var CleanRow = '';
      var StartCount = 0;
      
      jQuery(document).ready(function()
      {
          if ($('#lines').length > 0)
          { 
0df09c49   andryeyev   + fix по стилю ме...
64
              StartCount = $('#lines').children().last().attr('id');
c52bd933   andryeyev   - удаление модифи...
65
66
67
68
69
70
71
72
73
74
75
76
              
              if (empty(StartCount)) {
                  StartCount='line1';
              }
              
              c = StartCount.substr(4);    
           
              CopyCleanRow();
              SumPerRow(); 
          }
      });
  
42868d70   andryeyev   Создал GIT
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
      function CopyCleanRow () {    // ==== Êîïèðóåì ÷èñòóþ ñòðîêó  ====
      
          CleanRow = document.getElementById('line0').innerHTML;
      }
  
      function AddRow () {    // ==== Äîáàâëåì ñòðîêó è ìåíÿåì èíäåêñ ==== 
          
          c++;
       
          // ñîçäàåì div
          var div = document.createElement ('div');
              div.setAttribute('id', 'line'+c);
              
          // çàìåíÿåì àðãóìåíò ôóíêöèè RemoveDiv(0) íà íîìåð íîâîé ñòðîêè RemoveDiv(1)
          divContent= CleanRow.replace(/(\()(\d+\))/gi,'$1'+c+')');
              
          // èùåì ðîäèòåëñêèé êîíòåéíåð parent = document.getElementById ('line'+(c-1)).parentNode;
          var parent = document.getElementById ('line'+(0)).parentNode;
          
          // äîáàâëÿåì íàø <div id='line'>
          parent.appendChild (div);
          
          // çàïîëíÿåì åãî ñêîïèðîâàíûéì div
          document.getElementById('line'+c).innerHTML=divContent;
  
          // äîáàâëÿåì ðÿä íîìåð ñ
          document.getElementById('id('+c+')').innerHTML=c;
      }
  
      function RemoveDivLine(num) {
  
          div='line'+num;
  		RemoveDiv(div);
  
          // åñëè óäàëèëè âñå ñòðîêè äîáàâëÿåì íîâóþ
0df09c49   andryeyev   + fix по стилю ме...
112
          var StartCount= $('#lines').children().last().attr('id');
42868d70   andryeyev   Создал GIT
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
          if (empty(StartCount)) {
              c=0;
              AddRow();
          }
          
          // ñóììèðóåì
          SumPerRow();
          
          return false;
      }
  	
      function DDivLine(num) {
  
          div='line'+num;
         // document.getElementById('priceValue('+num+')').value = 0;
          document.getElementById('quantValue('+num+')').value = 0;		
          document.getElementById(div).style.background="#ffc5c5";
  		//RemoveDiv(div);
  
          // åñëè óäàëèëè âñå ñòðîêè äîáàâëÿåì íîâóþ
0df09c49   andryeyev   + fix по стилю ме...
133
          var StartCount= $('#lines').children().last().attr('id');
42868d70   andryeyev   Создал GIT
134
135
136
137
138
139
140
141
142
143
144
145
146
          if (empty(StartCount)) {
              c=0;
              AddRow();
          }
          
          // ñóììèðóåì
          SumPerRow();
          
          return false;
      }	
          
      function flyFind(value, number) {    // ==== flyFind  ==== 
  
84f56040   andryeyev   + Редактирование ...
147
148
149
150
151
          $.post("/ajax/flySearch.php", {
              load:'search',what: ""+value+"", row_number: number}, function(data,textStatus)
          {
              if (data!=0) 
              {
42868d70   andryeyev   Создал GIT
152
153
154
                  window.document.getElementById('livesearch'+number).innerHTML=data;
                  // Ïîêàçûâàåì îêíî
                  document.getElementById('livesearch'+number).style.display='block';
84f56040   andryeyev   + Редактирование ...
155
156
              } 
          });
42868d70   andryeyev   Создал GIT
157
158
  
          return false;
42868d70   andryeyev   Создал GIT
159
160
161
162
163
164
      }  
      
      function displaySearch(id){
          document.getElementById(id).style.display = ('' == document.getElementById(id).style.display)? '' : 'none';
      }
      
42868d70   andryeyev   Создал GIT
165
166
      function selectFirst(key) {    // ==== Ñòðåëêà âíèç ïåðâûé åëåìåíò èç ñïèñêà ==== 
  
84f56040   andryeyev   + Редактирование ...
167
168
169
170
171
172
          // Mozilla
          if(key == 40) 
          {
              window.document.getElementById('searchSelect('+c+')').focus();
              window.document.getElementById('searchSelect('+c+')').selectedIndex=0;
          }
42868d70   andryeyev   Создал GIT
173
  
84f56040   andryeyev   + Редактирование ...
174
          return false;
42868d70   andryeyev   Создал GIT
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
      }
   
      function SubmitForm(key) {    // ==== ENTER - âñòàâêà âûáðàíîãî ïóíêòà ìåíþ ==== 
  
           //Mozilla
           if (key==13) {
                showSelected();
           }
           
           return false;
      }
  
      function showSelected(c){    // ==== Âûáîðêà è çàïîëíåíèå ==== 
  
          // Ïîëó÷àåì çíà÷åíèå    
          var _obj = document.getElementById('searchSelect('+c+')');
          _value=document.getElementById('code('+c+')');
          
          // Âûáèðàåì ÷òî íóæíî
          var selIndex = _obj.selectedIndex;
          _value.value = _obj.options[selIndex].value;
          _value.text =_obj.options[selIndex].text;
          
          // Ðàçáèâàåì íà çíà÷åíèÿ
          var iArray = _value.value.split("|");
          var iArrayTitle = _value.text.split("|");
  
          // Çàïîëíÿåì
          //  code, mod_id, product_id, brend_id, brend, price â êà÷åñòâå option
          document.getElementById('code('+c+')').value = iArray[0];
          // document.getElementById('mod_id('+c+')').innerHTML = iArray[1];
          document.getElementById('mod_idValue('+c+')').value = iArray[1];
          // document.getElementById('product_id('+c+')').innerHTML = iArray[2];
          document.getElementById('product_idValue('+c+')').value = iArray[2];
          document.getElementById('brand('+c+')').innerHTML = iArray[4];
          document.getElementById('brand_idValue('+c+')').value = iArray[3];
          document.getElementById('price('+c+')').innerHTML = iArray[5]+' ãðí.';
          document.getElementById('priceValue('+c+')').value = iArray[5];
          document.getElementById('total('+c+')').innerHTML = iArray[5]+' ãðí.';    
          document.getElementById('totalValue('+c+')').value = iArray[5];
          
          document.getElementById('color('+c+')').innerHTML = iArray[7]; 
          document.getElementById('size('+c+')').innerHTML = iArray[8]; 
  
          document.getElementById('title('+c+')').innerHTML = iArrayTitle[0];
          document.getElementById('onstock('+c+')').innerHTML = iArrayTitle[1];
          
          // Ñêðûâàåì îêíî
          document.getElementById('livesearch('+c+')').style.display='none';
          
          // ==== Ïåðåñ÷åò çàêàçà ====     
          SumPerRow();
          
      } 
  
      function SumPerRow(){    // ==== Ïåðåñ÷åò çàêàçà ====  
  
          var Summary=0;
          var TotalQuantity=0;
          
          for(i=0; i<=c; i++) {
  
              price=document.getElementById('priceValue('+i+')');
          
              if(!empty(price)) {
              
                  price=parseFloat(document.getElementById('priceValue('+i+')').value);
                  quant=parseFloat(document.getElementById('quantValue('+i+')').value);
  
  
                  
                  TotalPerRow=quant * price;
                  Quantity=quant;
                  
                  document.getElementById('totalValue('+i+')').value =    TotalPerRow;
                  document.getElementById('total('+i+')').innerHTML  =    TotalPerRow +' ãðí.';
                  
                  Summary+=TotalPerRow;
                  TotalQuantity+=Quantity;
              
              }
  
          }
              document.getElementById('quantity').innerHTML  =    TotalQuantity-1;
              document.getElementById('summary').innerHTML   =    Summary;
              document.getElementById('summaryValue').value  =    Summary;
      }
      
      // ============== 
      // === Email ==== 
      // ============== 
      
      function livesearchEmail(value) {    // ==== livesearchEmail  ==== 
  
                $.post("/ajax/flySearch.php", {load:'searchEmail',what: ""+value+""}, function(data,textStatus){
                if (data!=0) {
                  window.document.getElementById('livesearch-email-list').innerHTML=data;
                  // Ïîêàçûâàåì îêíî
                  document.getElementById('livesearch-email-list').style.display='block';
                }
                        
           });
  
  
          return false;
  
      }  
      
      function SelectEmail(){    // ==== Âûáîðêà è çàïîëíåíèå ==== 
  
          // Ïîëó÷àåì çíà÷åíèå    
          var _obj = document.getElementById('choose-email');
          _value=document.getElementById('emailValue');
          
          // Âûáèðàåì ÷òî íóæíî
          var selIndex = _obj.selectedIndex;
          _value.value = _obj.options[selIndex].value;
          
          // Ðàçáèâàåì íà çíà÷åíèÿ
          var iArray = _value.value.split("|");
  
          // Çàïîëíÿåì
          //  id,username,email,tel,tel2,city,adress â êà÷åñòâå option
          document.getElementById('usernameValue').value = iArray[1];
          document.getElementById('emailValue').value = iArray[2];
          document.getElementById('telValue').value = iArray[3];
          document.getElementById('tel2Value').value = iArray[4];
          document.getElementById('cityValue').value = iArray[5];        
          document.getElementById('addressValue').value = iArray[6];
          
          if(isset('usergroup')) { document.getElementById('usergroup').value = iArray[7]; }
          if(isset('user_id')) { document.getElementById('user_id').value = iArray[0];}
          
          // Ñêðûâàåì îêíî
          document.getElementById('livesearch-email-list').style.display='none';
          
      } 
      
      function SelectEmailFirst(key) {    // ==== Ñòðåëêà âíèç ïåðâûé åëåìåíò èç ñïèñêà ==== 
  
           // Mozilla
           if(key==40) {
                window.document.getElementById('livesearch-email-list').focus();
                window.document.getElementById('livesearch-email-list').selectedIndex=0;
           }
  
        return false;
  
      }
   
      function SelectEmailSubmit(key) {    // ==== ENTER - âñòàâêà âûáðàíîãî ïóíêòà ìåíþ ==== 
  
           //Mozilla
           if (key==13) {
                SelectEmail();
           }
           
           return false;
      }
      
      // ============== 
      // ==== Tel ===== 
      // ============== 
      
84f56040   andryeyev   + Редактирование ...
339
340
341
342
343
344
      function livesearchTel(value)
      {
          $.post("/ajax/flySearch.php", {load:'searchTel',what: ""+value+""}, function(data,textStatus)
          {
              if (data!=0) 
              {
42868d70   andryeyev   Создал GIT
345
346
347
                  window.document.getElementById('livesearch-tel-list').innerHTML=data;
                  // Ïîêàçûâàåì îêíî
                  document.getElementById('livesearch-tel-list').style.display='block';
84f56040   andryeyev   + Редактирование ...
348
349
350
              } 
          });
   
42868d70   andryeyev   Создал GIT
351
352
353
354
          return false;
  
      }  
      
84f56040   andryeyev   + Редактирование ...
355
356
      function SelectTel()
      {
42868d70   andryeyev   Создал GIT
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
          // Ïîëó÷àåì çíà÷åíèå    
          var _obj = document.getElementById('choose-tel');
          _value=document.getElementById('telValue');
          
          // Âûáèðàåì ÷òî íóæíî
          var selIndex = _obj.selectedIndex;
          _value.value = _obj.options[selIndex].value;
          
          // Ðàçáèâàåì íà çíà÷åíèÿ
          var iArray = _value.value.split("|");
  
          // Çàïîëíÿåì
          //  id,username,email,tel,tel2,city,adress â êà÷åñòâå option
          document.getElementById('usernameValue').value = iArray[1];
          document.getElementById('emailValue').value = iArray[2];
          document.getElementById('telValue').value = iArray[3];
  		document.getElementById('telValue').focus();
          document.getElementById('tel2Value').value = iArray[4];
          document.getElementById('cityValue').value = iArray[5];        
          document.getElementById('addressValue').value = iArray[6];
          
          if(isset('usergroup')) { document.getElementById('usergroup').value = iArray[7]; }
          if(isset('user_id')) { document.getElementById('user_id').value = iArray[0];}
          
          // Ñêðûâàåì îêíî
          document.getElementById('livesearch-tel-list').style.display='none';
          
      } 
      
84f56040   andryeyev   + Редактирование ...
386
387
388
389
390
391
392
393
      function SelectTelFirst(key) 
      {
          // Mozilla
          if (key == 40) 
          {
              window.document.getElementById('livesearch-tel-list').focus();
              window.document.getElementById('livesearch-tel-list').selectedIndex=0;
          }
42868d70   andryeyev   Создал GIT
394
  
84f56040   andryeyev   + Редактирование ...
395
          return false;
42868d70   andryeyev   Создал GIT
396
397
      }
   
84f56040   andryeyev   + Редактирование ...
398
399
400
401
402
403
404
405
406
      function SelectTelSubmit(key) 
      {    
          // ENTER - âñòàâêà âûáðàíîãî ïóíêòà ìåíþ 
  
          // Mozilla
          if (key == 13) 
          {
              SelectTel();
          }
42868d70   andryeyev   Создал GIT
407
  
84f56040   andryeyev   + Редактирование ...
408
          return false;
42868d70   andryeyev   Создал GIT
409
      }
84f56040   andryeyev   + Редактирование ...
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
   
      function telAction ($array)
      {  
          $.ajax({
              type: 'GET',
              url: '/ajax/OrderContol.php',
              dataType: 'json', 
              data: $.param ($array['json']),
              success: function (response)
              {
                  switch ($array['json']['jaction']) 
                  { 
                      case 'tel-save': 
                      	 
                      	modalBoxLoad (response.html, {
                      		autoClose: 800, 
                      	}); 
                  		break;
                  }
              },
              error: function()
              {
              	modalBoxLoad ('×òî-òî ïîøëî íå òàê...');
              }  
          });
  /*
          $.post({ 
              url: '/js/OrderContol.php?jaction=' + $array['json']['jaction'],
              queryString: 1,
          })
          .done(function (response)
          {  	
          	modalBoxLoad (response.html, {
          		autoClose: 600, 
          	}); 
          })
          .fail (function()
          {
              modalBoxLoad ('×òî-òî ïîøëî íå òàê...');
          });
   */
      }   
  
      // ===================== 
      // ==== unknownUser ====
      // =====================     
42868d70   andryeyev   Создал GIT
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
      
      function newUnknownUser() {
      
          if(document.getElementById('default').checked) {
          
              var currentTime = new Date();
              var month       = currentTime.getMonth() + 1;
              var day         = currentTime.getDate();
              var year        = currentTime.getFullYear();
              var hour        = currentTime.getHours();
              var min         = currentTime.getMinutes();
              var sec         = currentTime.getSeconds();
              var currentDate = month + "/" + day + "/" + year + "/" + hour + "." + min + "." + sec;
              var currentTel  = '+380000000000';
  
              document.getElementById('emailValue').value = currentDate +'@user.com';
              document.getElementById('telValue').value =currentTel; 
              document.getElementById('usergroup').value = 1;
              document.getElementById('user_id').value = '0';
              document.getElementById('usernameValue').value = 'êëèåíò';
          }
      }
      
84f56040   andryeyev   + Редактирование ...
479
480
481
      // =======================
      // ==== userCheckData ==== 
      // ======================= 
42868d70   andryeyev   Создал GIT
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
      
      function userCheckData(value,fields) {    // ==== livesearchEmail  ==== 
  
                $.post("/ajax/flySearch.php", {load:'userCheckData',what: ""+value+"", field:fields}, function(data,textStatus){
                if (data!=0) {
                  window.document.getElementById('result-'+fields+'').innerHTML=data;
                  // Ïîêàçûâàåì îêíî
                  document.getElementById('result-'+fields+'').style.display='block';
                }
                        
           });
  
  
          return false;
  
      }  
84f56040   andryeyev   + Редактирование ...
498
499
500
501
   
  // ===================
  // ==== LISTENERS ====
  // ===================
42868d70   andryeyev   Создал GIT
502
  
84f56040   andryeyev   + Редактирование ...
503
504
  jQuery(document).ready(function()
  {
42868d70   andryeyev   Создал GIT
505
  
84f56040   andryeyev   + Редактирование ...
506
507
508
509
      $(".input_status").click(function() 
      { 
          $( "#status_box_"+$(this).attr("data-id") ).show();
      })
42868d70   andryeyev   Создал GIT
510
      
84f56040   andryeyev   + Редактирование ...
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
      $( ".status_box ul li.name_city" ).click(function()
      {
          $("#input_status_"+$(this).attr("data-id")).val($(this).text());
          $( ".status_box" ).hide();
      });
  
      $( ".status_box ul li.other" ).click(function()
      {
          $("#input_status_"+$(this).attr("data-id")).val("");
          $( ".status_box" ).hide();
          $("#input_status_"+$(this).attr("data-id")).focus();
      });	 
  
      $(".need-confirm").click(function(e)
      { 
          e.preventDefault();
42868d70   andryeyev   Создал GIT
527
      
84f56040   andryeyev   + Редактирование ...
528
529
530
531
          if (confirm ("Âû äåéñòâèòåëüíî æåëàåòå óäàëèòü?") == true) 
          {
              window.location = $(this).attr("href");
              
42868d70   andryeyev   Создал GIT
532
533
              return true;
          }
84f56040   andryeyev   + Редактирование ...
534
          
42868d70   andryeyev   Создал GIT
535
          return false;
84f56040   andryeyev   + Редактирование ...
536
      });
42868d70   andryeyev   Создал GIT
537
      
84f56040   andryeyev   + Редактирование ...
538
539
540
541
542
543
544
      $("#sms_tpl").change(function() 
      { 
          $.get("/ajax/sms_tpl.php", { tplID: this.value },function(data) {
              $("#sms_msg").val(data);
              $("#sms_c").html($("#sms_msg").val().length);
          });
      });
42868d70   andryeyev   Создал GIT
545
      
84f56040   andryeyev   + Редактирование ...
546
547
548
      $("#sms_send").click(function() 
      {
          if($("#sms_tel1").attr("checked") || $("#sms_tel2").attr("checked")) {
42868d70   andryeyev   Создал GIT
549
              return true;
84f56040   andryeyev   + Редактирование ...
550
551
          }else{
              alert("Íå óêàçàí íîìåð òåëåôîíà!");
42868d70   andryeyev   Создал GIT
552
553
              return false;
          }
84f56040   andryeyev   + Редактирование ...
554
      });
42868d70   andryeyev   Создал GIT
555
  
84f56040   andryeyev   + Редактирование ...
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
      w=120;
  
      $("input[name=\'sms_type\']").click(function() 
      { 
          i = $("#sms_msg").val().length;
          if(this.value=="l"){w=120;if(i>w){$("#sms_c").css( "color","red" );}else{$("#sms_c").css( "color","black" );}}
          else{w=70;if(i>w){$("#sms_c").css( "color","red" );}else{$("#sms_c").css( "color","black" );}}
          $("#sms_c_sum").html(w);
      });
  
      $("#sms_c_sum").html(w);
  
      
      $("#sms_msg").keyup(function()
      {
          i = this.value.length;
          if(i>w){$("#sms_c").css( "color","red" );}
          else{$("#sms_c").css( "color","black" );}
          $("#sms_c").html(i);
      });
  
      // âàëèäàöèÿ ôîðìû
      // $("#add-item").validationEngine();
      
      
      // Òåëåôîí 
fdaf43e8   andryeyev   + fix bug с телеф...
582
      $('.info.tel input[type=text]').on('change', function() 
84f56040   andryeyev   + Редактирование ...
583
584
585
586
587
588
589
590
591
592
      {  
           telAction({
               'json': {
              	  'jaction': 'tel-save',
                    'field': $(this).attr('name'),
                    'value': $(this).val(),
                    'order_id': getUrlVars('order_ID'), 
               }
           });
      });
42868d70   andryeyev   Создал GIT
593
  
84f56040   andryeyev   + Редактирование ...
594
  });