Refactor : Coupon effect inputs are now more customisable (input text, select, ajax, etc.. are usable) and unlimited amount of input for coupon effect are now possible too (Event are used for custom inputs)

This commit is contained in:
gmorel
2013-12-26 23:47:07 +01:00
parent 8f9b86ff6a
commit e18298bbba
11 changed files with 170 additions and 21 deletions

View File

@@ -127,13 +127,42 @@ $(function($){
};
$.couponManager.onClickUpdateCondition();
$.couponManager.displayEfffect = function(optionSelected) {
var mainDiv = $('#coupon-type');
mainDiv.find('.typeToolTip').html(optionSelected.attr('data-description'));
var inputsDiv = mainDiv.find('.inputs');
inputsDiv.html('<div class="loading" ></div>');
var url = $.couponManager.urlAjaxAdminCouponDrawInputs;
url = url.replace('couponServiceId', optionSelected.val());
$.ajax({
type: "GET",
url: url,
data: '',
statusCode: {
404: function() {
inputsDiv.html($.couponManager.intlPleaseRetry);
},
500: function() {
inputsDiv.html($.couponManager.intlPleaseRetry);
}
}
}).done(function(data) {
inputsDiv.html(data);
});
};
// Reload effect inputs when changing effect
$.couponManager.onEffectChange = function() {
var optionSelected = $("option:selected", this);
$('#effectToolTip').html(optionSelected.attr("data-description"));
$('#effect').on('change', function () {
var optionSelected = $("option:selected", this);
$('#effectToolTip').html(optionSelected.attr("data-description"));
var mainDiv = $('#coupon-type');
var optionSelected = mainDiv.find('#type option:selected');
mainDiv.find('.typeToolTip').html(optionSelected.attr('data-description'));
mainDiv.find('#type').on('change', function () {
var optionSelected = $('option:selected', this);
$.couponManager.displayEfffect(optionSelected);
});
};
$.couponManager.onEffectChange();

View File

@@ -59,6 +59,11 @@
filemanager_title:"{intl l='Files manager'}" ,
external_plugins: { "filemanager" : "{url file='/tinymce/plugins/filemanager/plugin.min.js'}"}
});
// Url alowing to get coupon inputs
$.couponManager.urlAjaxAdminCouponDrawInputs = "{$urlAjaxAdminCouponDrawInputs}";
$.couponManager.intlPleaseRetry = '{intl l='Please retry'}';
</script>
{/block}

View File

@@ -36,6 +36,8 @@
<script src="{$asset_url}"></script>
{/javascripts}
<script>
</script>
{javascripts file='assets/js/coupon.js'}
<script src="{$asset_url}"></script>
{/javascripts}
@@ -62,6 +64,10 @@
$(function($){
// miniBrowser(0, '/test_to_remove/datas_coupon_edit.json');
// Url alowing to get coupon inputs
$.couponManager.urlAjaxAdminCouponDrawInputs = "{$urlAjaxAdminCouponDrawInputs}";
$.couponManager.intlPleaseRetry = '{intl l='Please retry'}';
// Init Conditions
$.couponManager.initConditions = function() {
var conditions = [];

View File

@@ -99,32 +99,28 @@
</div>
<div class="col-md-8">
<div class="well clearfix">
<div id="coupon-type" class="well clearfix">
<div class="col-md-6">
{form_field form=$form field='type'}
<div class="form-group {if $error}has-error{/if}">
<label for="type" class="control-label">{intl l='Type :'}</label>
<select name="{$name}" id="type" class="col-md-12 form-control">
<option value="-1" data-description="">{intl l='Please select a coupon type'}</option>
<option value="-1" data-description="" data-inputName="">{intl l='Please select a coupon type'}</option>
{foreach from=$availableCoupons item=availableCoupon}
<option value="{$availableCoupon.serviceId}" {if $value == $availableCoupon.serviceId}selected{/if}>
<option value="{$availableCoupon.serviceId}" data-description="{$availableCoupon.toolTip}" data-inputName="{$availableCoupon.inputName}" {if $value == $availableCoupon.serviceId}selected{/if}>
{$availableCoupon.name}
</option>
{/foreach}
</select>
{if $error}{$message}{/if}
<span id="typeToolTip" class="help-block">{$availableCoupons.0.toolTip}</span>
<span class="help-block typeToolTip">{$availableCoupons.0.toolTip}</span>
</div>
{/form_field}
</div>
<div class="col-md-6">
<div class="col-md-6 inputs">
{form_field form=$form field='amount'}
<div class="form-group {if $error}has-error{/if}">
<label for="amount" class="control-label">{intl l='Amount :'}</label>
<input id="amount" type="text" class="form-control" name="{$name}" value="{$value}" placeholder="{intl l='14.50'}">
{if $error}{$message}{/if}
</div>
{$couponInputsHtml nofilter}
{/form_field}
{*<div class="form-group {if $error}has-error{/if}">*}
{*<label for="category">Category :</label>*}
@@ -208,7 +204,7 @@
<select name="categoryCondition" id="category-condition" class="form-control">
<option value="-1" >{intl l='Please select a condition category'}</option>
{foreach from=$availableConditions item=availableCondition}
<option value="{$availableCondition.serviceId}" data-description="{$availableCondition.toolTip}">{$availableCondition.name}</option>
<option value="{$availableCondition.serviceId}" >{$availableCondition.name}</option>
{/foreach}
</select>
</div>