Coupon : Condition module refactor
Less crappy unmaintainable javascript More logic in extendable php
This commit is contained in:
@@ -2,124 +2,126 @@ $(function($){
|
||||
|
||||
// Manage how coupon and conditions are saved
|
||||
$.couponManager = {};
|
||||
// Condition to be saved
|
||||
$.couponManager.conditionToSave = {};
|
||||
$.couponManager.conditionToSave.serviceId = false;
|
||||
$.couponManager.conditionToSave.operators = {};
|
||||
$.couponManager.conditionToSave.values = {};
|
||||
// Conditions payload to save
|
||||
$.couponManager.conditionsToSave = [];
|
||||
// Condition being updated id
|
||||
$.couponManager.conditionToUpdateId = false;
|
||||
|
||||
// Clean array from deleteValue (undefined) keys
|
||||
Array.prototype.clean = function(deleteValue) {
|
||||
for (var i = 0; i < this.length; i++) {
|
||||
if (this[i] == deleteValue) {
|
||||
this.splice(i, 1);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
// Condition being updated category id
|
||||
$.couponManager.conditionToUpdateServiceId = -1;
|
||||
// Condition being updated index
|
||||
$.couponManager.conditionToUpdateIndex = false;
|
||||
|
||||
// Remove 1 Condition then Save Conditions AJAX
|
||||
$.couponManager.removeConditionAjax = function(id) {
|
||||
// Delete condition in temporary array
|
||||
delete $.couponManager.conditionsToSave[id];
|
||||
$.couponManager.conditionsToSave.clean(undefined);
|
||||
// AJAX urls
|
||||
$.couponManager.urlAjaxSaveConditions = '';
|
||||
$.couponManager.urlAjaxDeleteConditions = '';
|
||||
$.couponManager.urlAjaxGetConditionSummaries = '';
|
||||
$.couponManager.urlAjaxAdminCouponDrawInputs = '';
|
||||
$.couponManager.urlAjaxGetConditionInputFromServiceId = '';
|
||||
$.couponManager.urlAjaxGetConditionInputFromConditionInterface = '';
|
||||
|
||||
// Save
|
||||
$.couponManager.saveConditionAjax();
|
||||
};
|
||||
|
||||
// Add 1 Condition / or update the temporary Conditions array then Save Conditions via AJAX
|
||||
$.couponManager.createOrUpdateConditionAjax = function() {
|
||||
var id = $.couponManager.conditionToUpdateId;
|
||||
// If create
|
||||
if(!id) {
|
||||
$.couponManager.conditionsToSave.push($.couponManager.conditionToSave);
|
||||
} else { // else update
|
||||
$.couponManager.conditionsToSave[id] = $.couponManager.conditionToSave;
|
||||
// reset edit mode to off
|
||||
$.couponManager.conditionToUpdateId = false;
|
||||
}
|
||||
|
||||
// Save
|
||||
$.couponManager.saveConditionAjax();
|
||||
};
|
||||
|
||||
// Set condition inputs to allow editing
|
||||
$.couponManager.updateConditionSelectAjax = function(id) {
|
||||
$.couponManager.conditionToUpdateId = id;
|
||||
$.couponManager.conditionToSave = $.couponManager.conditionsToSave[id];
|
||||
|
||||
// Set the condition selector
|
||||
$("#category-condition option").filter(function() {
|
||||
return $(this).val() == $.couponManager.conditionToSave.serviceId;
|
||||
}).prop('selected', true);
|
||||
|
||||
// Force condition input refresh
|
||||
$.couponManager.loadConditionInputs($.couponManager.conditionToSave.serviceId, function() {
|
||||
$.couponManager.fillInConditionInputs();
|
||||
});
|
||||
};
|
||||
|
||||
// Fill in condition inputs
|
||||
$.couponManager.fillInConditionInputs = function() {
|
||||
var operatorId = null;
|
||||
var valueId = null;
|
||||
var idName = null;
|
||||
|
||||
var id = $.couponManager.conditionToUpdateId;
|
||||
if(id) {
|
||||
$.couponManager.conditionToSave = $.couponManager.conditionsToSave[id];
|
||||
}
|
||||
|
||||
for (idName in $.couponManager.conditionToSave.operators) {
|
||||
// Setting idName operator select
|
||||
operatorId = idName + '-operator';
|
||||
$('#' + operatorId).val($.couponManager.conditionToSave.operators[idName]);
|
||||
|
||||
// Setting idName value input
|
||||
valueId = idName + '-value';
|
||||
$('#' + valueId).val($.couponManager.conditionToSave.values[idName]);
|
||||
}
|
||||
};
|
||||
|
||||
// Save conditions on click
|
||||
$.couponManager.onClickSaveCondition = function() {
|
||||
$('#condition-save-btn').on('click', function () {
|
||||
if($('#category-condition').val() == 'thelia.condition.match_for_everyone') {
|
||||
// // @todo translate message + put it in modal
|
||||
var r = confirm("Do you really want to set this coupon available to everyone ?");
|
||||
if (r == true) {
|
||||
$.couponManager.createOrUpdateConditionAjax();
|
||||
}
|
||||
} else {
|
||||
$.couponManager.createOrUpdateConditionAjax();
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
$.couponManager.onClickSaveCondition();
|
||||
// I18n messages
|
||||
$.couponManager.intlPleaseRetry = '';
|
||||
$.couponManager.intlPleaseSelectAnotherCondition = '';
|
||||
$.couponManager.intlDoYouReallyWantToSetCouponAvailableForEveryOne = '';
|
||||
|
||||
// *****************************************
|
||||
// ****************** Delete ***************
|
||||
// *****************************************
|
||||
// Remove condition on click
|
||||
$.couponManager.onClickDeleteCondition = function() {
|
||||
$('.condition-delete-btn').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var $this = $(this);
|
||||
$.couponManager.removeConditionAjax($this.attr('data-int'));
|
||||
var index = $this.attr('data-conditionIndex');
|
||||
$.couponManager.conditionToUpdateServiceId = -1;
|
||||
$.couponManager.conditionToUpdateIndex = false;
|
||||
$.couponManager.removeConditionAjax(index);
|
||||
});
|
||||
};
|
||||
$.couponManager.onClickDeleteCondition();
|
||||
|
||||
// Remove 1 Condition
|
||||
$.couponManager.removeConditionAjax = function(index) {
|
||||
var url = $.couponManager.urlAjaxDeleteConditions;
|
||||
url = url.replace('8888888', index);
|
||||
|
||||
$('#condition-list').html('<div class="loading" ></div>');
|
||||
$.ajax({
|
||||
url: url,
|
||||
statusCode: {
|
||||
404: function() {
|
||||
$('#condition-list').html($.couponManager.intlPleaseSelectAnotherCondition);
|
||||
},
|
||||
500: function() {
|
||||
$('#condition-list').html($.couponManager.intlPleaseSelectAnotherCondition);
|
||||
}
|
||||
}
|
||||
}).done(function(data) {
|
||||
// Reload condition summaries ajax
|
||||
$.couponManager.displayConditionsSummary();
|
||||
});
|
||||
};
|
||||
|
||||
// *****************************************
|
||||
// ****************** Save *****************
|
||||
// *****************************************
|
||||
|
||||
// Save conditions on click
|
||||
$.couponManager.onClickSaveCondition = function() {
|
||||
$('#condition-save-btn').on('click', function () {
|
||||
if ($('#category-condition').val() == 'thelia.condition.match_for_everyone') {
|
||||
var r = confirm($.couponManager.intlDoYouReallyWantToSetCouponAvailableForEveryOne);
|
||||
if (r == true) {
|
||||
$.couponManager.saveConditionAjax();
|
||||
}
|
||||
} else {
|
||||
$.couponManager.saveConditionAjax();
|
||||
}
|
||||
});
|
||||
};
|
||||
$.couponManager.onClickSaveCondition();
|
||||
|
||||
// Save Conditions AJAX
|
||||
$.couponManager.saveConditionAjax = function() {
|
||||
var $form = $("#condition-form");
|
||||
var data = $form.serialize();
|
||||
var url = $form.attr('action');
|
||||
url = url.replace('8888888', $.couponManager.conditionToUpdateIndex);
|
||||
$('#condition-add-operators-values').html('<div class="loading" ></div>');
|
||||
|
||||
$.post(
|
||||
url,
|
||||
data
|
||||
).done(function() {
|
||||
$.couponManager.displayConditionsSummary();
|
||||
$('#condition-add-operators-values').html('');
|
||||
// Set the condition selector to default
|
||||
$("#category-condition option").filter(function() {
|
||||
return $(this).val() == '-1';
|
||||
}).prop('selected', true);
|
||||
}).fail(function() {
|
||||
$('#condition-add-operators-values').html(
|
||||
$.couponManager.intlPleaseRetry
|
||||
);
|
||||
}).always(function() {
|
||||
// Reload condition summaries ajax
|
||||
$.couponManager.displayConditionsSummary();
|
||||
});
|
||||
};
|
||||
|
||||
// *****************************************
|
||||
// ****************** Update****************
|
||||
// *****************************************
|
||||
|
||||
// Update condition on click
|
||||
$.couponManager.onClickUpdateCondition = function() {
|
||||
$('.condition-update-btn').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var $this = $(this);
|
||||
$.couponManager.updateConditionSelectAjax($this.attr('data-int'));
|
||||
$.couponManager.conditionToUpdateServiceId = $this.attr('data-serviceId');
|
||||
$.couponManager.conditionToUpdateIndex = $this.attr('data-conditionIndex');
|
||||
|
||||
$.couponManager.updateConditionSelectFromConditionInterfaceAjax(
|
||||
$.couponManager.conditionToUpdateIndex,
|
||||
$.couponManager.conditionToUpdateServiceId
|
||||
);
|
||||
|
||||
// Hide row being updated
|
||||
$this.parent().parent().remove();
|
||||
@@ -127,33 +129,82 @@ $(function($){
|
||||
};
|
||||
$.couponManager.onClickUpdateCondition();
|
||||
|
||||
$.couponManager.displayEfffect = function(optionSelected) {
|
||||
var mainDiv = $('#coupon-type');
|
||||
mainDiv.find('.typeToolTip').html(optionSelected.attr('data-description'));
|
||||
// Reload condition inputs when changing Condition type
|
||||
$.couponManager.onConditionChange = function() {
|
||||
$('#category-condition').on('change', function () {
|
||||
var $this = $(this);
|
||||
// Only if add mode
|
||||
if (false != $.couponManager.conditionToUpdateIndex) {
|
||||
// Reload condition summaries ajax
|
||||
$.couponManager.displayConditionsSummary();
|
||||
}
|
||||
$.couponManager.conditionToUpdateServiceId = $this.val();
|
||||
$.couponManager.conditionToUpdateIndex = false;
|
||||
$.couponManager.loadConditionInputsFromServiceId($this.val());
|
||||
});
|
||||
};
|
||||
$.couponManager.onConditionChange();
|
||||
|
||||
var inputsDiv = mainDiv.find('.inputs');
|
||||
inputsDiv.html('<div class="loading" ></div>');
|
||||
var url = $.couponManager.urlAjaxAdminCouponDrawInputs;
|
||||
console.log(url);
|
||||
url = url.replace('couponServiceId', optionSelected.val());
|
||||
console.log(url);
|
||||
// Set condition inputs in order to allow editing
|
||||
$.couponManager.updateConditionSelectFromConditionInterfaceAjax = function(conditionIndex, serviceId) {
|
||||
// Force condition input refresh
|
||||
$.couponManager.loadConditionInputsFromConditionInterface(conditionIndex);
|
||||
|
||||
// Set the condition selector
|
||||
$("#category-condition option").filter(function() {
|
||||
return $(this).val() == serviceId;
|
||||
}).prop('selected', true);
|
||||
};
|
||||
|
||||
// Reload condition inputs AJAX
|
||||
$.couponManager.doAjaxloadConditionInputs = function(url) {
|
||||
$('#condition-add-operators-values').html('<div class="loading" ></div>');
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: url,
|
||||
data: '',
|
||||
statusCode: {
|
||||
404: function() {
|
||||
inputsDiv.html($.couponManager.intlPleaseRetry);
|
||||
$('#condition-add-operators-values').html(
|
||||
$.couponManager.intlPleaseSelectAnotherCondition
|
||||
);
|
||||
},
|
||||
500: function() {
|
||||
inputsDiv.html($.couponManager.intlPleaseRetry);
|
||||
$('#condition-add-operators-values').html(
|
||||
$.couponManager.intlPleaseSelectAnotherCondition
|
||||
);
|
||||
}
|
||||
}
|
||||
}).done(function(data) {
|
||||
inputsDiv.html(data);
|
||||
$('#condition-add-operators-values').html(data);
|
||||
if ($.couponManager.conditionToUpdateServiceId == -1) {
|
||||
// Placeholder can't be saved
|
||||
$('#condition-save-btn').hide();
|
||||
} else {
|
||||
$('#condition-save-btn').show();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Reload condition inputs from Condition ServiceId
|
||||
$.couponManager.loadConditionInputsFromServiceId = function(conditionServiceId) {
|
||||
var url = $.couponManager.urlAjaxGetConditionInputFromServiceId;
|
||||
url = url.replace('conditionId', conditionServiceId);
|
||||
|
||||
return $.couponManager.doAjaxloadConditionInputs(url);
|
||||
};
|
||||
// Reload condition inputs from Condition index
|
||||
$.couponManager.loadConditionInputsFromConditionInterface = function(conditionIndex) {
|
||||
var url = $.couponManager.urlAjaxGetConditionInputFromConditionInterface;
|
||||
url = url.replace('8888888', conditionIndex);
|
||||
|
||||
return $.couponManager.doAjaxloadConditionInputs(url);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// ***********************************************
|
||||
// *************** Manager Coupon ****************
|
||||
// ***********************************************
|
||||
// Reload effect inputs when changing effect
|
||||
$.couponManager.onEffectChange = function() {
|
||||
var mainDiv = $('#coupon-type');
|
||||
@@ -168,28 +219,65 @@ $(function($){
|
||||
};
|
||||
$.couponManager.onEffectChange();
|
||||
|
||||
// Reload condition inputs when changing effect
|
||||
$.couponManager.onConditionChange = function() {
|
||||
$('#category-condition').on('change', function () {
|
||||
$.couponManager.loadConditionInputs($(this).val(), function() {});
|
||||
$.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);
|
||||
});
|
||||
};
|
||||
$.couponManager.onConditionChange();
|
||||
|
||||
// Fill in ready to be saved condition array
|
||||
// var onInputsChange = function()
|
||||
// In AJAX response
|
||||
$.couponManager.displayConditionsSummary = function() {
|
||||
var mainDiv = $('#condition-list');
|
||||
mainDiv.html('<div class="loading" ></div>');
|
||||
var url = $.couponManager.urlAjaxGetConditionSummaries;
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: url,
|
||||
data: '',
|
||||
statusCode: {
|
||||
404: function() {
|
||||
mainDiv.html($.couponManager.intlPleaseRetry);
|
||||
},
|
||||
500: function() {
|
||||
mainDiv.html($.couponManager.intlPleaseRetry);
|
||||
}
|
||||
}
|
||||
}).done(function(data) {
|
||||
mainDiv.html(data);
|
||||
$.couponManager.onClickUpdateCondition();
|
||||
$.couponManager.onClickDeleteCondition();
|
||||
});
|
||||
};
|
||||
|
||||
// Set max usage to unlimited or not
|
||||
$.couponManager.onUsageUnlimitedChange = function() {
|
||||
var $isUnlimited = $('#is-unlimited');
|
||||
if ($('#max-usage').val() == -1) {
|
||||
$maxUsage = $('#max-usage');
|
||||
if ($maxUsage.val() == -1) {
|
||||
$isUnlimited.prop('checked', true);
|
||||
$('#max-usage').hide();
|
||||
$maxUsage.hide();
|
||||
$('#max-usage-label').hide();
|
||||
} else {
|
||||
$isUnlimited.prop('checked', false);
|
||||
$('#max-usage').show();
|
||||
$maxUsage.show();
|
||||
$('#max-usage-label').show();
|
||||
}
|
||||
|
||||
@@ -205,8 +293,4 @@ $(function($){
|
||||
});
|
||||
};
|
||||
$.couponManager.onUsageUnlimitedChange();
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
@@ -64,6 +64,7 @@
|
||||
// Url alowing to get coupon inputs
|
||||
$.couponManager.urlAjaxAdminCouponDrawInputs = "{$urlAjaxAdminCouponDrawInputs}";
|
||||
$.couponManager.intlPleaseRetry = '{intl l='Please retry'}';
|
||||
$.couponManager.intlDoYouReallyWantToSetCouponAvailableForEveryOne = '{intl l='Do you really want to set this coupon available to everyone ?'}';
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
{$TOOLTIP}
|
||||
{$SUMMARY}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
@@ -36,8 +36,6 @@
|
||||
<script src="{$asset_url}"></script>
|
||||
{/javascripts}
|
||||
|
||||
<script>
|
||||
</script>
|
||||
{javascripts file='assets/js/coupon.js'}
|
||||
<script src="{$asset_url}"></script>
|
||||
{/javascripts}
|
||||
@@ -62,94 +60,19 @@
|
||||
});
|
||||
|
||||
$(function($){
|
||||
// miniBrowser(0, '/test_to_remove/datas_coupon_edit.json');
|
||||
|
||||
// Url alowing to get coupon inputs
|
||||
$.couponManager.urlAjaxAdminCouponDrawInputs = "{$urlAjaxAdminCouponDrawInputs}";
|
||||
$.couponManager.urlAjaxSaveConditions = '{$urlAjaxSaveConditions}';
|
||||
$.couponManager.urlAjaxDeleteConditions = '{$urlAjaxDeleteConditions}';
|
||||
$.couponManager.urlAjaxGetConditionSummaries = '{$urlAjaxGetConditionSummaries}';
|
||||
$.couponManager.urlAjaxAdminCouponDrawInputs = '{$urlAjaxAdminCouponDrawInputs}';
|
||||
$.couponManager.urlAjaxGetConditionInputFromServiceId = '{$urlAjaxGetConditionInputFromServiceId}';
|
||||
$.couponManager.urlAjaxGetConditionInputFromConditionInterface = '{$urlAjaxGetConditionInputFromConditionInterface}';
|
||||
$.couponManager.intlPleaseRetry = '{intl l='Please retry'}';
|
||||
|
||||
// Init Conditions
|
||||
$.couponManager.initConditions = function() {
|
||||
var conditions = [];
|
||||
{foreach from=$conditionsObject key=k item=condition}
|
||||
// Init condition
|
||||
var condition = {};
|
||||
condition['serviceId'] = '{$condition.serviceId nofilter}';
|
||||
condition['operators'] = {};
|
||||
condition['values'] = {};
|
||||
|
||||
{foreach from=$condition.validators.setOperators key=input item=operator}
|
||||
condition['operators']['{$input nofilter}'] = '{$operator nofilter}';
|
||||
condition['values']['{$input nofilter}'] = '{$condition.validators.setValues[$input] nofilter}';
|
||||
{/foreach}
|
||||
|
||||
// Add condition
|
||||
conditions.push(condition);
|
||||
{/foreach}
|
||||
|
||||
return conditions;
|
||||
};
|
||||
|
||||
// Save Conditions AJAX
|
||||
$.couponManager.saveConditionAjax = function() {
|
||||
$('#condition-add-operators-values').html('<div class="loading" ></div>');
|
||||
var $url = '{$urlAjaxUpdateConditions}';
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: $url,
|
||||
data: {literal}{{/literal}conditions:JSON.stringify($.couponManager.conditionsToSave){literal}}{/literal},
|
||||
statusCode: {
|
||||
404: function() {
|
||||
$('#condition-add-operators-values').html(
|
||||
'{intl l='Please retry'}'
|
||||
);
|
||||
}
|
||||
}
|
||||
}).done(function(data) {
|
||||
$('#condition-list').html(data);
|
||||
$('#condition-add-operators-values').html('');
|
||||
// Set the condition selector
|
||||
$("#category-condition option").filter(function() {
|
||||
return $(this).val() == 'thelia.condition.match_for_everyone';
|
||||
}).prop('selected', true);
|
||||
|
||||
$.couponManager.onClickUpdateCondition();
|
||||
$.couponManager.onClickDeleteCondition();
|
||||
});
|
||||
};
|
||||
|
||||
// Reload condition inputs
|
||||
$.couponManager.loadConditionInputs = function(conditionId, callBack) {
|
||||
$('#condition-add-operators-values').html('<div class="loading" ></div>');
|
||||
var url = "{$urlAjaxGetConditionInput}";
|
||||
url = url.replace('conditionId', conditionId)
|
||||
$.ajax({
|
||||
url: url,
|
||||
statusCode: {
|
||||
404: function() {
|
||||
$('#condition-add-operators-values').html(
|
||||
'{intl l='Please select another condition'}'
|
||||
);
|
||||
}
|
||||
}
|
||||
}).done(function(data) {
|
||||
$('#condition-add-operators-values').html(data);
|
||||
$.couponManager.conditionToSave.serviceId = conditionId;
|
||||
if (conditionId == -1) {
|
||||
// Placeholder can't be saved
|
||||
$('#condition-save-btn').hide();
|
||||
} else {
|
||||
$('#condition-save-btn').show();
|
||||
}
|
||||
return callBack();
|
||||
});
|
||||
};
|
||||
|
||||
// Conditions which will be saved
|
||||
$.couponManager.conditionsToSave = $.couponManager.initConditions();
|
||||
$.couponManager.intlPleaseSelectAnotherCondition = '{intl l='Please select another condition'}';
|
||||
$.couponManager.intlDoYouReallyWantToSetCouponAvailableForEveryOne = '{intl l='Do you really want to set this coupon available to everyone ?'}';
|
||||
|
||||
$('#condition-save-btn').hide();
|
||||
|
||||
});
|
||||
</script>
|
||||
{/block}
|
||||
|
||||
@@ -1,104 +1,7 @@
|
||||
{foreach from=$inputs.inputs key=name item=input}
|
||||
<label for="operator">{$input.title}</label>
|
||||
<div class="row">
|
||||
<div class="col-lg-6">
|
||||
<select class="form-control" id="{$name}-operator" name="{$name}[operator]">
|
||||
{foreach from=$input.availableOperators key=k item=availableOperator name=availableOperators}
|
||||
<option value="{$k}">{$availableOperator}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</div>
|
||||
<div class="input-group col-lg-6">
|
||||
{if $input.type == 'select'}
|
||||
<select class="{$input.class}" id="{$name}-value" name="{$name}[value]">
|
||||
{foreach from=$input.availableValues key=code item=availableValue name=availableValues}
|
||||
<option value="{$code}">{$availableValue}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
{else}
|
||||
<input type="{$input.type}" class="{$input.class}" id="{$name}-value" name="{$name}[value]">
|
||||
{*<span class="input-group-addon">€</span>*}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/foreach}
|
||||
{*<label for="operator">Operator :</label>*}
|
||||
{*<div class="row">*}
|
||||
{*<div class="col-lg-6">*}
|
||||
{*<select class="form-control" id="operator" name="operator">*}
|
||||
{*<option value="1">is superior to</option>*}
|
||||
{*<option value="2">equals to</option>*}
|
||||
{*<option value="3">is inferior to</option>*}
|
||||
{*<option value="4">is inferior or equals to</option>*}
|
||||
{*<option value="5">is superior or equals to</option>*}
|
||||
{*</select>*}
|
||||
{*</div>*}
|
||||
{*<div data-date-format="dd/mm/yyyy" data-date="12/02/2012" class="input-group col-lg-6 date">*}
|
||||
{*<input type="text" class="form-control" name="value">*}
|
||||
{*<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>*}
|
||||
{*</div>*}
|
||||
{*</div>*}
|
||||
{*<label for="operator">Operator :</label>*}
|
||||
{*<div class="row">*}
|
||||
{*<div class="col-lg-6">*}
|
||||
{*<select class="form-control" id="operator" name="operator">*}
|
||||
{*<option value="1">is superior to</option>*}
|
||||
{*<option value="2">equals to</option>*}
|
||||
{*<option value="3">is inferior to</option>*}
|
||||
{*<option value="4">is inferior or equals to</option>*}
|
||||
{*<option value="5">is superior or equals to</option>*}
|
||||
{*</select>*}
|
||||
{*</div>*}
|
||||
{*<div class="col-lg-6">*}
|
||||
{*<input type="text" class="form-control" name="value">*}
|
||||
{*</div>*}
|
||||
{*</div>*}
|
||||
{*<div class="row">*}
|
||||
{*<div class="col-lg-12">*}
|
||||
{*<table class="table table-bordered">*}
|
||||
{*<tbody><tr>*}
|
||||
{*<td id="minibrowser-breadcrumb"><div><span> > </span><a href="#">Racine</a></div></td>*}
|
||||
{*</tr>*}
|
||||
{*<tr>*}
|
||||
{*<th><span class="icon-th-list"></span> Categories list</th>*}
|
||||
{*</tr>*}
|
||||
{*<tr>*}
|
||||
{*<td id="minibrowser-categories"><div><p><a href="#">Boyaux</a></p><p><a href="#">Epices / condiments</a></p><p><a href="#">Emballage</a></p><p><a href="#">Petits matériels</a></p><p><a href="#">Materiel de cuisine</a></p><p><a href="#">Bacs</a></p><p><a href="#">Hygiène & entretien</a></p><p><a href="#">Art de la table</a></p><p><a href="#">Matériels</a></p></div></td>*}
|
||||
{*</tr>*}
|
||||
{*</tbody></table>*}
|
||||
{*</div>*}
|
||||
{*</div>*}
|
||||
{$inputsDrawn nofilter}
|
||||
|
||||
<input name="conditionIndex" type="hidden" value="{$conditionIndex}" />
|
||||
|
||||
<script>
|
||||
|
||||
// Init conditions to set
|
||||
// Update only if no condition are already set
|
||||
if(!$.couponManager.conditionToSave){
|
||||
$.couponManager.conditionToSave['serviceId'] = '{$conditionId}';
|
||||
$.couponManager.conditionToSave['operators'] = {literal}{}{/literal};
|
||||
$.couponManager.conditionToSave['values'] = {literal}{}{/literal};
|
||||
} else {
|
||||
}
|
||||
{foreach from=$inputs.inputs key=name item=input}
|
||||
$.couponManager.conditionToSave['operators']['{$name nofilter}'] = '{foreach from=$inputs.inputs[$name].availableOperators key=keyOperator item=valueOperator name=operators}{if $smarty.foreach.operators.first}{$keyOperator nofilter}{/if}{/foreach}';
|
||||
$.couponManager.conditionToSave['values']['{$name nofilter}'] = '{if count($inputs.inputs[$name].availableValues) != 0}{foreach from=$inputs.inputs[$name].availableValues key=keyValue item=valueValue name=values}{if $smarty.foreach.values.first}{$keyValue nofilter}{/if}{/foreach}{else}to set{/if}';
|
||||
{/foreach}
|
||||
|
||||
|
||||
// Fill in ready to be saved condition array
|
||||
$.couponManager.onInputsChange = function() {literal}{{/literal}
|
||||
{foreach from=$inputs.inputs key=name item=input}
|
||||
// Operator selector
|
||||
$('#{$name}-operator').change(function (e) {
|
||||
var $this = $(this);
|
||||
$.couponManager.conditionToSave['operators']['{$name nofilter}'] = $this.val();
|
||||
});
|
||||
// Value input
|
||||
$('#{$name}-value').change(function (e) {
|
||||
var $this = $(this);
|
||||
$.couponManager.conditionToSave['values']['{$name nofilter}'] = $this.val();
|
||||
});
|
||||
{/foreach}
|
||||
{literal}}{/literal}
|
||||
$.couponManager.onInputsChange();
|
||||
$.couponManager.conditionToUpdateServiceId = '{$conditionServiceId}';
|
||||
</script>
|
||||
@@ -1,17 +1,18 @@
|
||||
{* List all condition with their summary *}
|
||||
{foreach from=$conditions item=condition key=i name=conditionsForeach}
|
||||
<tr>
|
||||
<td>
|
||||
{if !$smarty.foreach.conditionsForeach.first}
|
||||
<span class="label label-info">{intl l='And'}</span>
|
||||
{/if}
|
||||
{$condition nofilter}
|
||||
{$condition.summary nofilter}
|
||||
</td>
|
||||
<td>
|
||||
<a data-int="{$i}" class="btn btn-default btn-primary btn-medium condition-update-btn" href="{$urlEdit}">
|
||||
<a data-serviceId="{$condition.serviceId}" data-conditionIndex="{$condition.index}" class="btn btn-default btn-primary btn-medium condition-update-btn" href="{$urlEdit}">
|
||||
<span class="glyphicon glyphicon-edit"></span> {intl l='Edit'}
|
||||
</a>
|
||||
{if $conditions|count != 1}
|
||||
<a data-int="{$i}" data-target="#delete" data-toggle="confirm" class="btn btn-default btn-danger btn-medium condition-delete-btn" href="{$urlDelete}">
|
||||
<a data-conditionIndex="{$condition.index}" data-target="#delete" data-toggle="confirm" class="btn btn-default btn-danger btn-medium condition-delete-btn" href="{$urlDelete}">
|
||||
<span class="glyphicon glyphicon-remove"></span> {intl l='Delete'}
|
||||
</a>
|
||||
{/if}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
{$thelia_page_css_file = "assets/bootstrap-editable/css/bootstrap-editable.css"}
|
||||
{include file='includes/notifications.html' message=$general_error}
|
||||
<form action="{$formAction}" {form_enctype form=$form} method="POST" >
|
||||
<section class="row">
|
||||
|
||||
<section class="row">
|
||||
<form action="{$formAction}" {form_enctype form=$form} method="POST" >
|
||||
<div class="col-md-12 general-block-decorator">
|
||||
|
||||
{form_hidden_fields form=$form}
|
||||
@@ -122,17 +123,6 @@
|
||||
{form_field form=$form field='amount'}
|
||||
{$couponInputsHtml nofilter}
|
||||
{/form_field}
|
||||
{*<div class="form-group {if $error}has-error{/if}">*}
|
||||
{*<label for="category">Category :</label>*}
|
||||
{*form_field form=$form field='category'*}
|
||||
{*<select name="{$name}" value="{$value}" id="category" class="form-control">*}
|
||||
{*<option value="1">Category 1</option>*}
|
||||
{*<option value="1">Category 2</option>*}
|
||||
{*<option value="1">Category 3</option>*}
|
||||
{*</select>*}
|
||||
{*if $error}{$message}{/if}*}
|
||||
{*/form_field*}
|
||||
{*</div>*}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -160,30 +150,33 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</section>
|
||||
{if $noConditions}
|
||||
{include file='includes/notifications.html' message={intl l='Please save your Coupon in oder to affect it some conditions'}}
|
||||
{else}
|
||||
<section class="row">
|
||||
<div class="col-md-12 general-block-decorator">
|
||||
<table class="table table-striped">
|
||||
<caption class="clearfix">
|
||||
{intl l='Conditions'}
|
||||
</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{intl l='Conditions'}</th>
|
||||
<th>{intl l='Actions'}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="condition-list">
|
||||
{include file='coupon/conditions.html' conditions=$conditions}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section class="row">
|
||||
{if $noConditions}
|
||||
{include file='includes/notifications.html' message={intl l='Please save your Coupon in oder to affect it some conditions'}}
|
||||
{else}
|
||||
<section class="row">
|
||||
<div class="col-md-12 general-block-decorator">
|
||||
<table class="table table-striped">
|
||||
<caption class="clearfix">
|
||||
{intl l='Conditions'}
|
||||
</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{intl l='Conditions'}</th>
|
||||
<th>{intl l='Actions'}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="condition-list">
|
||||
{include file='coupon/conditions.html' conditions=$conditions}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="row">
|
||||
<form id="condition-form" action="{$urlAjaxSaveConditions}" {form_enctype form=$form} method="POST" >
|
||||
<div class="col-md-12 general-block-decorator clearfix">
|
||||
<a id="condition-save-btn" title="{intl l='Save this condition'}" class="btn btn-default btn-primary pull-right" data-toggle="confirm" data-script="">
|
||||
<span class="glyphicon glyphicon-plus-sign"></span> {intl l='Save this condition'}
|
||||
@@ -209,74 +202,9 @@
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div id="condition-add-operators-values" class="form-group col-md-6">
|
||||
{*<label for="operator">{intl l='Operator :'}</label>*}
|
||||
{*<div class="row">*}
|
||||
{*<div class="col-lg-6">*}
|
||||
{*<select name="operator" id="operator" class="form-control">*}
|
||||
{*<option value="1">is superior to</option>*}
|
||||
{*<option value="2">equals to</option>*}
|
||||
{*<option value="3">is inferior to</option>*}
|
||||
{*<option value="4">is inferior or equals to</option>*}
|
||||
{*<option value="5">is superior or equals to</option>*}
|
||||
{*</select>*}
|
||||
{*</div>*}
|
||||
{*<div class="input-group col-lg-6">*}
|
||||
{*<input type="text" name="value" class="form-control">*}
|
||||
{*<span class="input-group-addon">€</span>*}
|
||||
{*</div>*}
|
||||
{*</div>*}
|
||||
{**}
|
||||
|
||||
{*<label for="operator">Operator :</label>*}
|
||||
{*<div class="row">*}
|
||||
{*<div class="col-lg-6">*}
|
||||
{*<select name="operator" id="operator" class="form-control">*}
|
||||
{*<option value="1">is superior to</option>*}
|
||||
{*<option value="2">equals to</option>*}
|
||||
{*<option value="3">is inferior to</option>*}
|
||||
{*<option value="4">is inferior or equals to</option>*}
|
||||
{*<option value="5">is superior or equals to</option>*}
|
||||
{*</select>*}
|
||||
{*</div>*}
|
||||
{*<div class="input-group col-lg-6 date" data-date="12/02/2012" data-date-format="dd/mm/yyyy">*}
|
||||
{*<input type="text" name="value" class="form-control">*}
|
||||
{*<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>*}
|
||||
{*</div>*}
|
||||
{*</div>*}
|
||||
|
||||
{*<label for="operator">Operator :</label>*}
|
||||
{*<div class="row">*}
|
||||
{*<div class="col-lg-6">*}
|
||||
{*<select name="operator" id="operator" class="form-control">*}
|
||||
{*<option value="1">is superior to</option>*}
|
||||
{*<option value="2">equals to</option>*}
|
||||
{*<option value="3">is inferior to</option>*}
|
||||
{*<option value="4">is inferior or equals to</option>*}
|
||||
{*<option value="5">is superior or equals to</option>*}
|
||||
{*</select>*}
|
||||
{*</div>*}
|
||||
{*<div class="col-lg-6">*}
|
||||
{*<input type="text" name="value" class="form-control">*}
|
||||
{*</div>*}
|
||||
{*</div>*}
|
||||
{*<div class="row">*}
|
||||
{*<div class="col-lg-12">*}
|
||||
{*<table class="table table-bordered">*}
|
||||
{*<tr>*}
|
||||
{*<td id="minibrowser-breadcrumb"></td>*}
|
||||
{*</tr>*}
|
||||
{*<tr>*}
|
||||
{*<th><span class="icon-th-list"></span> Categories list</th>*}
|
||||
{*</tr>*}
|
||||
{*<tr>*}
|
||||
{*<td id="minibrowser-categories"></td>*}
|
||||
{*</tr>*}
|
||||
{*</table>*}
|
||||
{*</div>*}
|
||||
{*</div>*}
|
||||
</div>
|
||||
<div id="condition-add-operators-values" class="form-group col-md-6"></div>
|
||||
</div>
|
||||
</section>
|
||||
{/if}
|
||||
</form>
|
||||
</form>
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user