| @@ -1,197 +1,195 @@ | ||
| 1 | -jQuery(function($) { | |
| 2 | - | |
| 3 | - codSend = { | |
| 4 | - settings: { | |
| 5 | - url: uscesL10n.requestFile, | |
| 6 | - type: 'POST', | |
| 7 | - cache: false, | |
| 8 | - success: function(data, dataType){ | |
| 9 | - var str = 'success' == data ? usces_ini.cod_updated : data; | |
| 10 | - $("#cod-response").html( str ); | |
| 11 | - if( 'fix' == $("input[name='cod_type']:checked").val() ){ | |
| 12 | - $('#cod_type_field').html(usces_ini.cod_type_fix); | |
| 13 | - }else if( 'change' == $("input[name='cod_type']:checked").val() ){ | |
| 14 | - $('#cod_type_field').html(usces_ini.cod_type_change); | |
| 15 | - } | |
| 16 | - }, | |
| 17 | - error: function(msg){ | |
| 18 | - $("#cod-response").html(usces_ini.cod_failure); | |
| 19 | - } | |
| 20 | - }, | |
| 21 | - | |
| 22 | - send : function() { | |
| 23 | - $("#cod-response").html('<img src="' + uscesL10n.USCES_PLUGIN_URL + '/images/loading-publish.gif" />'); | |
| 24 | - var query = 'action=setup_cod_ajax'; | |
| 25 | - var cod_type = $("input[name='cod_type']:checked").val(); | |
| 26 | - | |
| 27 | - if( 'fix' == cod_type ){ | |
| 28 | - var cod_fee = $("input[name='cod_fee']").val(); | |
| 29 | - var cod_limit_amount = $("#cod_limit_amount_fix").val(); | |
| 30 | - query += '&cod_type=' + cod_type + '&cod_fee=' + cod_fee + '&cod_limit_amount=' + cod_limit_amount; | |
| 31 | - }else{ | |
| 32 | - var cod_first_amount = $("input[name='cod_first_amount']").val(); | |
| 33 | - var cod_limit_amount = $("#cod_limit_amount_change").val(); | |
| 34 | - var cod_first_fee = $("input[name='cod_first_fee']").val(); | |
| 35 | - var cod_end_fee = $("input[name='cod_end_fee']").val(); | |
| 36 | - query += '&cod_type=' + cod_type + '&cod_first_amount=' + cod_first_amount + '&cod_limit_amount=' + cod_limit_amount + '&cod_first_fee=' + cod_first_fee + '&cod_end_fee=' + cod_end_fee; | |
| 37 | - var amounts = $("input[name^='cod_amounts']"); | |
| 38 | - for(var i=0; i<amounts.length; i++){ | |
| 39 | - query += '&cod_amounts[]=' + $("input[name='cod_amounts\[" + i + "\]']").val() + '&cod_fees[]=' + $("input[name='cod_fees\[" + i + "\]']").val(); | |
| 40 | - } | |
| 41 | - } | |
| 42 | - | |
| 43 | - | |
| 44 | - var s = codSend.settings; | |
| 45 | - s.data = query; | |
| 46 | - $.ajax( s ); | |
| 47 | - return false; | |
| 48 | - } | |
| 49 | - }; | |
| 50 | - | |
| 51 | - $("#cod_dialog").dialog({ | |
| 52 | - autoOpen: false, | |
| 53 | - height: 500, | |
| 54 | - width: 450, | |
| 55 | - modal: true, | |
| 56 | - buttons: { | |
| 57 | - 'Cancel' : function() { | |
| 58 | - $(this).dialog('close'); | |
| 59 | - }, | |
| 60 | - 'Update' : function() { | |
| 61 | - codSend.send(); | |
| 62 | - } | |
| 63 | - }, | |
| 64 | - close: function() { | |
| 65 | - if( 'fix' == $("input[name='cod_type']:checked").val() ){ | |
| 66 | - $('#cod_type_field').html(usces_ini.cod_type_fix); | |
| 67 | - }else if( 'change' == $("input[name='cod_type']:checked").val() ){ | |
| 68 | - $('#cod_type_field').html(usces_ini.cod_type_change); | |
| 69 | - } | |
| 70 | - } | |
| 71 | - }); | |
| 72 | - | |
| 73 | - $('#detailed_setting') | |
| 74 | - .click(function() { | |
| 75 | - $('#cod_dialog').dialog('open'); | |
| 76 | - }); | |
| 77 | - | |
| 78 | - $('#cod_type_fix') | |
| 79 | - .click(function() { | |
| 80 | - $('#cod_fix_table').css("display",""); | |
| 81 | - $('#cod_change_table').css("display","none"); | |
| 82 | - }); | |
| 83 | - | |
| 84 | - $('#cod_type_change') | |
| 85 | - .click(function() { | |
| 86 | - $('#cod_fix_table').css("display","none"); | |
| 87 | - $('#cod_change_table').css("display",""); | |
| 88 | - }); | |
| 89 | - | |
| 90 | - $("input[name='cod_first_amount']") | |
| 91 | - .change(function() { | |
| 92 | - var trs = $("input[name^='cod_amounts']"); | |
| 93 | - var first_amount = $("input[name='cod_first_amount']"); | |
| 94 | - if( 0 == trs.length && $(first_amount).val() != '' ){ | |
| 95 | - $("#end_amount").html(parseInt($(first_amount).val())+1); | |
| 96 | - }else if( 0 < trs.length && $(first_amount).val() != '' ){ | |
| 97 | - $('#amount_0').html(parseInt($(first_amount).val())+1); | |
| 98 | - } | |
| 99 | - | |
| 100 | - }); | |
| 101 | - | |
| 102 | - $("#cod_limit_amount_change") | |
| 103 | - .change(function() { | |
| 104 | - if( 'change' == $("input[name='cod_type']:checked").val() ){ | |
| 105 | - var pre = parseInt($("#end_amount").html()); | |
| 106 | - var limit = parseInt($("#cod_limit_amount_change").val()); | |
| 107 | - if( pre >= limit ){ | |
| 108 | - alert(usces_ini.cod_limit + pre + ':' + limit); | |
| 109 | - } | |
| 110 | - } | |
| 111 | - }); | |
| 112 | - | |
| 113 | - $("input[name^='cod_amounts']") | |
| 114 | - .change(function() { | |
| 115 | - var trs = $("input[name^='cod_amounts']"); | |
| 116 | - var cnt = $(trs).length; | |
| 117 | - var id = $(trs).index(this); | |
| 118 | - | |
| 119 | - if( id >= cnt-1 ){ | |
| 120 | - $(end_amount).html( parseInt($(trs).eq(id).val()) + 1 ); | |
| 121 | - }else if( id < cnt-1 ){ | |
| 122 | - $('#amount_'+(id+1)).html( parseInt($(trs).eq(id).val()) + 1 ); | |
| 123 | - } | |
| 124 | - }); | |
| 125 | - | |
| 126 | - $('#add_row') | |
| 127 | - .click(function() { | |
| 128 | - var trs = $("input[name^='cod_amounts']"); | |
| 129 | - $(trs).unbind("change"); | |
| 130 | - var first_amount = $("input[name='cod_first_amount']"); | |
| 131 | - var first_fee = $("input[name='cod_first_fee']"); | |
| 132 | - var end_amount = $("#end_amount"); | |
| 133 | - var enf_fee = $("input[name='cod_enf_fee']"); | |
| 134 | - //alert(parseInt(first_amount)+':'+first_fee+':'+end_amount+':'+enf_fee+':'+trs.length); | |
| 135 | - if( 0 == trs.length){ | |
| 136 | - prep = ( $(first_amount).val() == '' ) ? '' : parseInt( $(first_amount).val() )+1; | |
| 137 | - }else if( 0 < trs.length){ | |
| 138 | - prep = ( $(trs).eq(trs.length-1).val() == '' ) ? '' : parseInt( $(trs).eq(trs.length-1).val() )+1; | |
| 139 | - } | |
| 140 | - html = '<tr id="tr_'+trs.length+'"><td class="cod_f"><span id="amount_'+trs.length+'">' + prep + '</span></td><td class="cod_m">~</td><td class="cod_e"><input name="cod_amounts['+trs.length+']" type="text" class="short_str ui-widget-content ui-corner-all num" /></td><td class="cod_cod"><input name="cod_fees['+trs.length+']" type="text" class="short_str num" /></td></tr>'; | |
| 141 | - $('#cod_change_field').append(html); | |
| 142 | - trs = $("input[name^='cod_amounts']"); | |
| 143 | - $(trs).bind("change", function(){ | |
| 144 | - var cnt = $(trs).length; | |
| 145 | - var id = $(trs).index(this); | |
| 146 | - | |
| 147 | - if( id >= cnt-1 ){ | |
| 148 | - $(end_amount).html( parseInt($(trs).eq(id).val()) + 1 ); | |
| 149 | - }else if( id < cnt-1 ){ | |
| 150 | - $('#amount_'+(id+1)).html( parseInt($(trs).eq(id).val()) + 1 ); | |
| 151 | - } | |
| 152 | - return false; | |
| 153 | - }); | |
| 154 | - }); | |
| 155 | - | |
| 156 | - $('#del_row') | |
| 157 | - .click(function() { | |
| 158 | - var trs = $("input[name^='cod_amounts']"); | |
| 159 | - $(trs).unbind("change"); | |
| 160 | - var first_amount = $("input[name='cod_first_amount']"); | |
| 161 | - var end_amount = $("#end_amount"); | |
| 162 | - //alert(parseInt(first_amount)+':'+first_fee+':'+end_amount+':'+enf_fee+':'+trs.length); | |
| 163 | - var del_id = trs.length - 1; | |
| 164 | - //alert(trs.length); | |
| 165 | - if( 0 < trs.length){ | |
| 166 | - $('#tr_'+del_id).remove(); | |
| 167 | - } | |
| 168 | - trs = $("input[name^='cod_amounts']"); | |
| 169 | - if( 0 == trs.length && $(first_amount).val() != '' ){ | |
| 170 | - $(end_amount).html( parseInt($(first_amount).val())+1 ); | |
| 171 | - }else if( 0 < trs.length && $(trs).eq(trs.length-1).val() != '' ){ | |
| 172 | - $(end_amount).html( parseInt($(trs).eq(trs.length-1).val()) + 1 ); | |
| 173 | - } | |
| 174 | - $(trs).bind("change", function(){ | |
| 175 | - var cnt = $(trs).length; | |
| 176 | - var id = $(trs).index(this); | |
| 177 | - | |
| 178 | - if( id >= cnt-1 && $(trs).eq(id).val() != '' ){ | |
| 179 | - $(end_amount).html( parseInt($(trs).eq(id).val()) + 1 ); | |
| 180 | - }else if( id < cnt-1 && $(trs).eq(id).val() != '' ){ | |
| 181 | - $('#amount_'+(id+1)).html( parseInt($(trs).eq(id).val()) + 1 ); | |
| 182 | - } | |
| 183 | - }); | |
| 184 | - }); | |
| 185 | - | |
| 186 | - if( 'fix' == usces_ini.cod_type ){ | |
| 187 | - $('#cod_type_field').html(usces_ini.cod_type_fix); | |
| 188 | - $('#cod_fix_table').css("display",""); | |
| 189 | - $('#cod_change_table').css("display","none"); | |
| 190 | - }else{ | |
| 191 | - $('#cod_type_field').html(usces_ini.cod_type_change); | |
| 192 | - $('#cod_fix_table').css("display","none"); | |
| 193 | - $('#cod_change_table').css("display",""); | |
| 194 | - } | |
| 195 | - | |
| 196 | - | |
| 197 | -}); | |
| 1 | +jQuery(function($) { | |
| 2 | + | |
| 3 | + codSend = { | |
| 4 | + settings: { | |
| 5 | + url: uscesL10n.requestFile, | |
| 6 | + type: 'POST', | |
| 7 | + cache: false | |
| 8 | + }, | |
| 9 | + | |
| 10 | + send : function() { | |
| 11 | + $("#cod-response").html('<img src="' + uscesL10n.USCES_PLUGIN_URL + '/images/loading-publish.gif" />'); | |
| 12 | + var query = 'action=setup_cod_ajax&wc_nonce=' + $("#wc_nonce").val(); | |
| 13 | + var cod_type = $("input[name='cod_type']:checked").val(); | |
| 14 | + | |
| 15 | + if( 'fix' == cod_type ){ | |
| 16 | + var cod_fee = $("input[name='cod_fee']").val(); | |
| 17 | + var cod_limit_amount = $("#cod_limit_amount_fix").val(); | |
| 18 | + query += '&cod_type=' + cod_type + '&cod_fee=' + cod_fee + '&cod_limit_amount=' + cod_limit_amount; | |
| 19 | + }else{ | |
| 20 | + var cod_first_amount = $("input[name='cod_first_amount']").val(); | |
| 21 | + var cod_limit_amount = $("#cod_limit_amount_change").val(); | |
| 22 | + var cod_first_fee = $("input[name='cod_first_fee']").val(); | |
| 23 | + var cod_end_fee = $("input[name='cod_end_fee']").val(); | |
| 24 | + query += '&cod_type=' + cod_type + '&cod_first_amount=' + cod_first_amount + '&cod_limit_amount=' + cod_limit_amount + '&cod_first_fee=' + cod_first_fee + '&cod_end_fee=' + cod_end_fee; | |
| 25 | + var amounts = $("input[name^='cod_amounts']"); | |
| 26 | + for(var i=0; i<amounts.length; i++){ | |
| 27 | + query += '&cod_amounts[]=' + $("input[name='cod_amounts\[" + i + "\]']").val() + '&cod_fees[]=' + $("input[name='cod_fees\[" + i + "\]']").val(); | |
| 28 | + } | |
| 29 | + } | |
| 30 | + | |
| 31 | + var s = codSend.settings; | |
| 32 | + s.data = query; | |
| 33 | + $.ajax( s ).done(function( data ){ | |
| 34 | + var str = 'success' == data ? usces_ini.cod_updated : data; | |
| 35 | + $("#cod-response").html( str ); | |
| 36 | + if( 'fix' == $("input[name='cod_type']:checked").val() ){ | |
| 37 | + $('#cod_type_field').html(usces_ini.cod_type_fix); | |
| 38 | + }else if( 'change' == $("input[name='cod_type']:checked").val() ){ | |
| 39 | + $('#cod_type_field').html(usces_ini.cod_type_change); | |
| 40 | + } | |
| 41 | + }).fail(function( msg ){ | |
| 42 | + $("#cod-response").html(usces_ini.cod_failure); | |
| 43 | + }); | |
| 44 | + return false; | |
| 45 | + } | |
| 46 | + }; | |
| 47 | + | |
| 48 | + $("#cod_dialog").dialog({ | |
| 49 | + autoOpen: false, | |
| 50 | + height: 500, | |
| 51 | + width: 450, | |
| 52 | + modal: true, | |
| 53 | + buttons: [ | |
| 54 | + { | |
| 55 | + text: usces_ini.cod_label_close, | |
| 56 | + click: function() { | |
| 57 | + $(this).dialog('close'); | |
| 58 | + } | |
| 59 | + }, | |
| 60 | + { | |
| 61 | + text: usces_ini.cod_label_update, | |
| 62 | + click: function() { | |
| 63 | + codSend.send(); | |
| 64 | + } | |
| 65 | + } | |
| 66 | + ], | |
| 67 | + close: function() { | |
| 68 | + if( 'fix' == $("input[name='cod_type']:checked").val() ){ | |
| 69 | + $('#cod_type_field').html(usces_ini.cod_type_fix); | |
| 70 | + }else if( 'change' == $("input[name='cod_type']:checked").val() ){ | |
| 71 | + $('#cod_type_field').html(usces_ini.cod_type_change); | |
| 72 | + } | |
| 73 | + } | |
| 74 | + }); | |
| 75 | + | |
| 76 | + $('#detailed_setting') | |
| 77 | + .click(function() { | |
| 78 | + $('#cod_dialog').dialog('open'); | |
| 79 | + }); | |
| 80 | + | |
| 81 | + $('#cod_type_fix') | |
| 82 | + .click(function() { | |
| 83 | + $('#cod_fix_table').css("display",""); | |
| 84 | + $('#cod_change_table').css("display","none"); | |
| 85 | + }); | |
| 86 | + | |
| 87 | + $('#cod_type_change') | |
| 88 | + .click(function() { | |
| 89 | + $('#cod_fix_table').css("display","none"); | |
| 90 | + $('#cod_change_table').css("display",""); | |
| 91 | + }); | |
| 92 | + | |
| 93 | + $("input[name='cod_first_amount']") | |
| 94 | + .change(function() { | |
| 95 | + var trs = $("input[name^='cod_amounts']"); | |
| 96 | + var first_amount = $("input[name='cod_first_amount']"); | |
| 97 | + if( 0 == trs.length && $(first_amount).val() != '' ){ | |
| 98 | + $("#end_amount").html(parseInt($(first_amount).val())+1); | |
| 99 | + }else if( 0 < trs.length && $(first_amount).val() != '' ){ | |
| 100 | + $('#amount_0').html(parseInt($(first_amount).val())+1); | |
| 101 | + } | |
| 102 | + }); | |
| 103 | + | |
| 104 | + $("#cod_limit_amount_change") | |
| 105 | + .change(function() { | |
| 106 | + if( 'change' == $("input[name='cod_type']:checked").val() ){ | |
| 107 | + var pre = parseInt($("#end_amount").html()); | |
| 108 | + var limit = parseInt($("#cod_limit_amount_change").val()); | |
| 109 | + if( pre >= limit ){ | |
| 110 | + alert(usces_ini.cod_limit + pre + ':' + limit); | |
| 111 | + } | |
| 112 | + } | |
| 113 | + }); | |
| 114 | + | |
| 115 | + $("input[name^='cod_amounts']") | |
| 116 | + .change(function() { | |
| 117 | + var trs = $("input[name^='cod_amounts']"); | |
| 118 | + var cnt = $(trs).length; | |
| 119 | + var id = $(trs).index(this); | |
| 120 | + if( id >= cnt-1 ){ | |
| 121 | + $(end_amount).html( parseInt($(trs).eq(id).val()) + 1 ); | |
| 122 | + }else if( id < cnt-1 ){ | |
| 123 | + $('#amount_'+(id+1)).html( parseInt($(trs).eq(id).val()) + 1 ); | |
| 124 | + } | |
| 125 | + }); | |
| 126 | + | |
| 127 | + $('#add_row') | |
| 128 | + .click(function() { | |
| 129 | + var trs = $("input[name^='cod_amounts']"); | |
| 130 | + $(trs).unbind("change"); | |
| 131 | + var first_amount = $("input[name='cod_first_amount']"); | |
| 132 | + var first_fee = $("input[name='cod_first_fee']"); | |
| 133 | + var end_amount = $("#end_amount"); | |
| 134 | + var enf_fee = $("input[name='cod_enf_fee']"); | |
| 135 | + //alert(parseInt(first_amount)+':'+first_fee+':'+end_amount+':'+enf_fee+':'+trs.length); | |
| 136 | + if( 0 == trs.length){ | |
| 137 | + prep = ( $(first_amount).val() == '' ) ? '' : parseInt( $(first_amount).val() )+1; | |
| 138 | + }else if( 0 < trs.length){ | |
| 139 | + prep = ( $(trs).eq(trs.length-1).val() == '' ) ? '' : parseInt( $(trs).eq(trs.length-1).val() )+1; | |
| 140 | + } | |
| 141 | + html = '<tr id="tr_'+trs.length+'"><td class="cod_f"><span id="amount_'+trs.length+'">' + prep + '</span></td><td class="cod_m">'+uscesL10n.message[20]+'</td><td class="cod_e"><input name="cod_amounts['+trs.length+']" type="text" class="short_str num" /></td><td class="cod_cod"><input name="cod_fees['+trs.length+']" type="text" class="short_str num" /></td></tr>'; | |
| 142 | + $('#cod_change_field').append(html); | |
| 143 | + trs = $("input[name^='cod_amounts']"); | |
| 144 | + $(trs).bind("change", function(){ | |
| 145 | + var cnt = $(trs).length; | |
| 146 | + var id = $(trs).index(this); | |
| 147 | + if( id >= cnt-1 ){ | |
| 148 | + $(end_amount).html( parseInt($(trs).eq(id).val()) + 1 ); | |
| 149 | + }else if( id < cnt-1 ){ | |
| 150 | + $('#amount_'+(id+1)).html( parseInt($(trs).eq(id).val()) + 1 ); | |
| 151 | + } | |
| 152 | + return false; | |
| 153 | + }); | |
| 154 | + }); | |
| 155 | + | |
| 156 | + $('#del_row') | |
| 157 | + .click(function() { | |
| 158 | + var trs = $("input[name^='cod_amounts']"); | |
| 159 | + $(trs).unbind("change"); | |
| 160 | + var first_amount = $("input[name='cod_first_amount']"); | |
| 161 | + var end_amount = $("#end_amount"); | |
| 162 | + //alert(parseInt(first_amount)+':'+first_fee+':'+end_amount+':'+enf_fee+':'+trs.length); | |
| 163 | + var del_id = trs.length - 1; | |
| 164 | + //alert(trs.length); | |
| 165 | + if( 0 < trs.length){ | |
| 166 | + $('#tr_'+del_id).remove(); | |
| 167 | + } | |
| 168 | + trs = $("input[name^='cod_amounts']"); | |
| 169 | + if( 0 == trs.length && $(first_amount).val() != '' ){ | |
| 170 | + $(end_amount).html( parseInt($(first_amount).val())+1 ); | |
| 171 | + }else if( 0 < trs.length && $(trs).eq(trs.length-1).val() != '' ){ | |
| 172 | + $(end_amount).html( parseInt($(trs).eq(trs.length-1).val()) + 1 ); | |
| 173 | + } | |
| 174 | + $(trs).bind("change", function(){ | |
| 175 | + var cnt = $(trs).length; | |
| 176 | + var id = $(trs).index(this); | |
| 177 | + | |
| 178 | + if( id >= cnt-1 && $(trs).eq(id).val() != '' ){ | |
| 179 | + $(end_amount).html( parseInt($(trs).eq(id).val()) + 1 ); | |
| 180 | + }else if( id < cnt-1 && $(trs).eq(id).val() != '' ){ | |
| 181 | + $('#amount_'+(id+1)).html( parseInt($(trs).eq(id).val()) + 1 ); | |
| 182 | + } | |
| 183 | + }); | |
| 184 | + }); | |
| 185 | + | |
| 186 | + if( 'fix' == usces_ini.cod_type ){ | |
| 187 | + $('#cod_type_field').html(usces_ini.cod_type_fix); | |
| 188 | + $('#cod_fix_table').css("display",""); | |
| 189 | + $('#cod_change_table').css("display","none"); | |
| 190 | + }else{ | |
| 191 | + $('#cod_type_field').html(usces_ini.cod_type_change); | |
| 192 | + $('#cod_fix_table').css("display","none"); | |
| 193 | + $('#cod_change_table').css("display",""); | |
| 194 | + } | |
| 195 | +}); | |