[+] BO: Add a wizard to create and edit your carriers
This commit is contained in:
@@ -0,0 +1,417 @@
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
bind_inputs();
|
||||
initCarrierWizard();
|
||||
});
|
||||
|
||||
function initCarrierWizard()
|
||||
{
|
||||
$("#carrier_wizard").smartWizard({
|
||||
'labelNext' : labelNext,
|
||||
'labelPrevious' : labelPrevious,
|
||||
'labelFinish' : labelFinish,
|
||||
'fixHeight' : 1,
|
||||
'onShowStep' : onShowStepCallback,
|
||||
'onLeaveStep' : onLeaveStepCallback,
|
||||
'onFinish' : onFinishCallback,
|
||||
'transitionEffect' : 'slideleft',
|
||||
'enableAllSteps' : enableAllSteps
|
||||
});
|
||||
displayRangeType();
|
||||
}
|
||||
|
||||
function displayRangeType()
|
||||
{
|
||||
if ($('input[name="shipping_method"]:checked').val() == 1)
|
||||
string = string_weight;
|
||||
else
|
||||
string = string_price;
|
||||
|
||||
$('.range_type').html(string);
|
||||
}
|
||||
|
||||
function onShowStepCallback()
|
||||
{
|
||||
$('.anchor li a').each( function () {
|
||||
$(this).parent('li').addClass($(this).attr('class'));
|
||||
});
|
||||
$('#carrier_logo_block').prependTo($('div.content').filter(function() { return $(this).css('display') != 'none' }).children('.defaultForm').children('fieldset'));
|
||||
resizeWizard();
|
||||
}
|
||||
|
||||
function onFinishCallback(obj, context)
|
||||
{
|
||||
$('.wizard_error').remove();
|
||||
$.ajax({
|
||||
type:"POST",
|
||||
url : validate_url,
|
||||
async: false,
|
||||
dataType: 'json',
|
||||
data : $('#carrier_wizard .stepContainer .content form').serialize() + '&action=finish_step&ajax=1',
|
||||
success : function(data) {
|
||||
if (data.has_error)
|
||||
{
|
||||
displayError(data.errors, context.fromStep);
|
||||
resizeWizard();
|
||||
}
|
||||
else
|
||||
window.location.href = carrierlist_url;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function onLeaveStepCallback(obj, context)
|
||||
{
|
||||
if (context.toStep == nbr_steps)
|
||||
displaySummary();
|
||||
|
||||
return validateSteps(context.fromStep); // return false to stay on step and true to continue navigation
|
||||
}
|
||||
|
||||
function displaySummary()
|
||||
{
|
||||
// used as buffer - you must not replace directly in the translation vars
|
||||
var tmp;
|
||||
|
||||
// Carrier name
|
||||
$('#summary_name').html($('#name').val());
|
||||
|
||||
// Delay and pricing
|
||||
tmp = summary_translation_meta_informations.replace('@s2', '<strong>' + $('#delay_1').val() + '</strong>');
|
||||
if ($('#is_free_on').attr('checked'))
|
||||
tmp = tmp.replace('@s1', summary_translation_free);
|
||||
else
|
||||
tmp = tmp.replace('@s1', summary_translation_paid);
|
||||
$('#summary_meta_informations').html(tmp);
|
||||
|
||||
// Tax and calculation mode for the shipping cost
|
||||
tmp = summary_translation_shipping_cost.replace('@s2', '<strong>' + $('#id_tax_rules_group option:selected').text() + '</strong>');
|
||||
if ($('#billing_price').attr('checked'))
|
||||
tmp = tmp.replace('@s1', summary_translation_price);
|
||||
else if ($('#billing_weight').attr('checked'))
|
||||
tmp = tmp.replace('@s1', summary_translation_weight);
|
||||
else
|
||||
tmp = tmp.replace('@s1', '<strong>' + summary_translation_undefined + '</strong>');
|
||||
$('#summary_shipping_cost').html(tmp);
|
||||
|
||||
// Weight or price ranges
|
||||
$('#summary_range').html(summary_translation_range);
|
||||
var range_inf = summary_translation_undefined;
|
||||
var range_sup = summary_translation_undefined;
|
||||
$('input[name$="range_inf[]"]').each(function(){
|
||||
if (!isNaN(parseFloat($(this).val())) && (range_inf == summary_translation_undefined || range_inf < $(this).val()))
|
||||
range_inf = $(this).val();
|
||||
});
|
||||
$('input[name$="range_sup[]"]').each(function(){
|
||||
if (!isNaN(parseFloat($(this).val())) && (range_sup == summary_translation_undefined || range_sup > $(this).val()))
|
||||
range_sup = $(this).val();
|
||||
});
|
||||
$('#summary_range').html(
|
||||
$('#summary_range').html()
|
||||
.replace('@s1', '<strong>' + range_inf + '</strong>')
|
||||
.replace('@s2', '<strong>' + range_sup + '</strong>')
|
||||
.replace('@s3', '<strong>' + $('#range_behavior option:selected').text().toLowerCase() + '</strong>')
|
||||
);
|
||||
|
||||
// Delivery zones
|
||||
$('#summary_zones').html('');
|
||||
$('.input_zone').each(function(){
|
||||
if ($(this).attr('checked'))
|
||||
$('#summary_zones').html($('#summary_zones').html() + '<li><strong>' + $(this).parent().prev().text() + '</strong></li>');
|
||||
});
|
||||
|
||||
// Group restrictions
|
||||
$('#summary_groups').html('');
|
||||
$('input[name$="groupBox[]"]').each(function(){
|
||||
if ($(this).attr('checked'))
|
||||
$('#summary_groups').html($('#summary_groups').html() + '<li><strong>' + $(this).parent().next().next().text() + '</strong></li>');
|
||||
});
|
||||
|
||||
// shop restrictions
|
||||
$('#summary_shops').html('');
|
||||
$('.input_shop').each(function(){
|
||||
if ($(this).attr('checked'))
|
||||
$('#summary_shops').html($('#summary_shops').html() + '<li><strong>' + $(this).parent().text() + '</strong></li>');
|
||||
});
|
||||
}
|
||||
|
||||
function validateSteps(step_number)
|
||||
{
|
||||
$('.wizard_error').remove();
|
||||
var is_ok = true;
|
||||
form = $('#carrier_wizard #step-'+step_number+' form');
|
||||
$.ajax({
|
||||
type:"POST",
|
||||
url : validate_url,
|
||||
async: false,
|
||||
dataType: 'json',
|
||||
data : form.serialize()+'&step_number='+step_number+'&action=validate_step&ajax=1',
|
||||
success : function(datas)
|
||||
{
|
||||
if (datas.has_error)
|
||||
{
|
||||
is_ok = false;
|
||||
|
||||
$('input').focus( function () {
|
||||
$(this).removeClass('field_error');
|
||||
});
|
||||
displayError(datas.errors, step_number);
|
||||
resizeWizard();
|
||||
}
|
||||
}
|
||||
});
|
||||
return is_ok;
|
||||
}
|
||||
|
||||
function displayError(errors, step_number)
|
||||
{
|
||||
$('.wizard_error').remove();
|
||||
str_error = '<div class="error wizard_error"><span style="float:right"><a id="hideError" href="#"><img alt="X" src="../img/admin/close.png" /></a></span><ul>';
|
||||
for (var error in errors)
|
||||
{
|
||||
$('#carrier_wizard').smartWizard('setError',{stepnum:step_number,iserror:true});
|
||||
$('input[name="'+error+'"]').addClass('field_error');
|
||||
str_error += '<li>'+errors[error]+'</li>';
|
||||
}
|
||||
$('#step-'+step_number).prepend(str_error+'</ul></div>');
|
||||
}
|
||||
|
||||
function resizeWizard()
|
||||
{
|
||||
resizeInterval = setInterval(function (){$("#carrier_wizard").smartWizard('fixHeight'); clearInterval(resizeInterval)}, 100);
|
||||
}
|
||||
|
||||
function bind_inputs()
|
||||
{
|
||||
$('tr.delete_range td button').off('click').on('click', function () {
|
||||
index = $(this).parent('td').index();
|
||||
$('tr.range_sup td:eq('+index+'), tr.range_inf td:eq('+index+'), tr.fees_all td:eq('+index+'), tr.delete_range td:eq('+index+')').remove();
|
||||
$('tr.fees').each( function () {
|
||||
$(this).children('td:eq('+index+')').remove();
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$('tr.fees_all td button').off('click').on('click', function () {
|
||||
index = $(this).parent('td').index();
|
||||
if (validateRange(index))
|
||||
enableRange(index);
|
||||
else
|
||||
disableRange(index);
|
||||
return false;
|
||||
});
|
||||
|
||||
$('tr.fees td input:checkbox').off('change').on('change', function () {
|
||||
|
||||
if($(this).is(':checked'))
|
||||
{
|
||||
$(this).closest('tr').children('td').each( function (){
|
||||
index = $(this).index();
|
||||
if ($('tr.fees_all td:eq('+index+')').hasClass('validated'))
|
||||
$(this).children('input:text').removeAttr('disabled');
|
||||
});
|
||||
}
|
||||
else
|
||||
$(this).closest('tr').children('td').children('input:text').attr('disabled', 'disabled');
|
||||
return false;
|
||||
});
|
||||
|
||||
$('tr.range_sup td input:text, tr.range_inf td input:text').focus( function () {
|
||||
$(this).removeClass('field_error');
|
||||
});
|
||||
|
||||
$('tr.range_sup td input:text, tr.range_inf td input:text').off('change').on('change', function () {
|
||||
index = $(this).parent('td').index();
|
||||
|
||||
if ($('tr.fees_all td:eq('+index+')').hasClass('validated') || $('tr.fees_all td:eq('+index+')').hasClass('not_validated'))
|
||||
{
|
||||
if (validateRange(index))
|
||||
enableRange(index);
|
||||
else
|
||||
disableRange(index);
|
||||
}
|
||||
});
|
||||
|
||||
$('tr.fees_all td input').off('change').on('change', function () {
|
||||
index = $(this).parent('td').index();
|
||||
val = $(this).val();
|
||||
$('tr.fees td input:text').not('disabled').val(val);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$('input[name="is_free"]').on('click', function() {
|
||||
var is_free = $(this);
|
||||
$("#step_carrier_ranges .margin-form").each(function() {
|
||||
var field = $(this).children().attr('name');
|
||||
if (typeof(field) != 'undefined' && field != 'is_free')
|
||||
{
|
||||
if (parseInt(is_free.val()))
|
||||
{
|
||||
$(this).hide();
|
||||
$(this).prev().hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
$(this).show();
|
||||
$(this).prev().show();
|
||||
}
|
||||
}
|
||||
});
|
||||
if (parseInt(is_free.val()))
|
||||
{
|
||||
$('#zones_table').hide();
|
||||
$('.new_range').hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#zones_table').show();
|
||||
$('.new_range').show();
|
||||
}
|
||||
});
|
||||
$('input[name="is_free"]:checked').click();
|
||||
|
||||
$('input[name="shipping_method"]').on('click', function() {
|
||||
$.ajax({
|
||||
type:"POST",
|
||||
url : validate_url,
|
||||
async: false,
|
||||
dataType: 'html',
|
||||
data : 'id_carrier='+parseInt($('#id_carrier').val())+'&shipping_method='+parseInt($(this).val())+'&action=changeRanges&ajax=1',
|
||||
success : function(data) {
|
||||
$('#zone_ranges').replaceWith(data);
|
||||
displayRangeType();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function validateRange(index)
|
||||
{
|
||||
//reset error css
|
||||
$('tr.range_sup td input:text').removeClass('field_error');
|
||||
$('tr.range_inf td input:text').removeClass('field_error');
|
||||
|
||||
is_ok = true;
|
||||
range_sup = parseInt($('tr.range_sup td:eq('+index+')').children('input:text').val().trim());
|
||||
range_inf = parseInt($('tr.range_inf td:eq('+index+')').children('input:text').val().trim());
|
||||
|
||||
if (isNaN(range_sup) || range_sup.length === 0)
|
||||
{
|
||||
$('tr.range_sup td:eq('+index+')').children('input:text').addClass('field_error');
|
||||
is_ok = false;
|
||||
}
|
||||
|
||||
if (isNaN(range_inf) || range_inf.length === 0)
|
||||
{
|
||||
$('tr.range_inf td:eq('+index+')').children('input:text').addClass('field_error');
|
||||
is_ok = false;
|
||||
}
|
||||
|
||||
if (is_ok)
|
||||
{
|
||||
if (range_inf >= range_sup)
|
||||
{
|
||||
$('tr.range_sup td:eq('+index+')').children('input:text').addClass('field_error');
|
||||
$('tr.range_inf td:eq('+index+')').children('input:text').addClass('field_error');
|
||||
is_ok = false;
|
||||
}
|
||||
//check if previous range is inf only if it's not the first range
|
||||
if (index > 2)
|
||||
{
|
||||
previous_range_sup = parseInt($('tr.range_sup td:eq('+(index -1)+')').children('input:text').val().trim());
|
||||
console.log(range_inf+' < '+previous_range_sup);
|
||||
if (range_inf < previous_range_sup)
|
||||
{
|
||||
$('tr.range_inf td:eq('+index+')').children('input:text').addClass('field_error');
|
||||
}
|
||||
}
|
||||
//check if next range is sup only if it's not the last range
|
||||
if ($('tr.range_inf td:eq('+(index + 1)+')').length)
|
||||
{
|
||||
next_range_inf = parseInt($('tr.range_inf td:eq('+(index +1)+')').children('input:text').val().trim());
|
||||
|
||||
if ((isNaN(range_sup) || range_sup.length === 0) && range_sup > next_range_inf)
|
||||
{
|
||||
$('tr.range_sup td:eq('+index+')').children('input:text').addClass('field_error');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return is_ok;
|
||||
}
|
||||
|
||||
function enableRange(index)
|
||||
{
|
||||
$('tr.fees').each( function () {
|
||||
//only enable fees for enabled zones
|
||||
if ($(this).children('td').children('input:checkbox').attr('checked') == 'checked')
|
||||
$(this).children('td:eq('+index+')').children('input').removeAttr('disabled');
|
||||
});
|
||||
$('span.fees_all').show();
|
||||
$('tr.fees_all td:eq('+index+')').children('input').show().removeAttr('disabled');
|
||||
$('tr.fees_all td:eq('+index+')').addClass('validated').removeClass('not_validated');
|
||||
$('tr.fees_all td:eq('+index+')').children('button').remove();
|
||||
}
|
||||
|
||||
function disableRange(index)
|
||||
{
|
||||
$('tr.fees').each( function () {
|
||||
//only enable fees for enabled zones
|
||||
if ($(this).children('td').children('input:checkbox').attr('checked') == 'checked')
|
||||
$(this).children('td:eq('+index+')').children('input').attr('disabled', 'disabled');
|
||||
});
|
||||
$('tr.fees_all td:eq('+index+')').children('input').attr('disabled', 'disabled');
|
||||
$('tr.fees_all td:eq('+index+')').removeClass('validated').addClass('not_validated');
|
||||
}
|
||||
|
||||
function add_new_range()
|
||||
{
|
||||
//add new rand sup input
|
||||
$('tr.range_sup td:last').after('<td class="center"><input name="range_sup[]" type="text" /></td>');
|
||||
//add new rand inf input
|
||||
$('tr.range_inf td:last').after('<td class="border_bottom center"><input name="range_inf[]" type="text" /></td>');
|
||||
|
||||
$('tr.fees_all td:last').after('<td class="center border_top border_bottom"><input style="display:none" type="text" /> <button class="button">'+labelValidate+'</button</td>');
|
||||
|
||||
$('tr.fees').each( function () {
|
||||
$(this).children('td:last').after('<td><input disabled="disabled" name="fees['+$(this).data('zoneid')+'][]" type="text" /></td>');
|
||||
});
|
||||
$('tr.delete_range td:last').after('<td class="center"><button class="button">'+labelDelete+'</button</td>');
|
||||
|
||||
resizeWizard();
|
||||
bind_inputs();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function delete_new_range()
|
||||
{
|
||||
if ($('#new_range_form_placeholder').children('td').length = 1)
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
/*
|
||||
SmartWizard 2.0 plugin
|
||||
jQuery Wizard control Plugin
|
||||
by Dipu
|
||||
|
||||
http://www.techlaboratory.net
|
||||
http://tech-laboratory.blogspot.com
|
||||
*/
|
||||
.swMain {
|
||||
position:relative;
|
||||
display:block;
|
||||
margin:0;
|
||||
padding:0;
|
||||
border: 0px solid #CCC;
|
||||
overflow:visible;
|
||||
float:left;
|
||||
width:980px;
|
||||
}
|
||||
.swMain .stepContainer {
|
||||
display:block;
|
||||
position: relative;
|
||||
margin: 0;
|
||||
padding:0;
|
||||
border: 0px solid #CCC;
|
||||
overflow:hidden;
|
||||
clear:both;
|
||||
height:300px;
|
||||
}
|
||||
|
||||
.swMain .stepContainer div.content {
|
||||
display:block;
|
||||
position: absolute;
|
||||
float:left;
|
||||
margin: 0;
|
||||
padding:5px;
|
||||
border: 1px solid #CCC;
|
||||
font: normal 12px Verdana, Arial, Helvetica, sans-serif;
|
||||
color:#5A5655;
|
||||
background-color:#F8F8F8;
|
||||
height:300px;
|
||||
text-align:left;
|
||||
overflow:visible;
|
||||
z-index:88;
|
||||
-webkit-border-radius: 5px;
|
||||
-moz-border-radius : 5px;
|
||||
width:968px;
|
||||
clear:both;
|
||||
}
|
||||
|
||||
.swMain div.actionBar {
|
||||
display:block;
|
||||
position: relative;
|
||||
clear:both;
|
||||
margin: 3px 0 0 0;
|
||||
border: 1px solid #CCC;
|
||||
padding: 0;
|
||||
color: #5A5655;
|
||||
background-color: #F8F8F8;
|
||||
height:40px;
|
||||
text-align:left;
|
||||
overflow:auto;
|
||||
z-index:88;
|
||||
|
||||
-webkit-border-radius: 5px;
|
||||
-moz-border-radius : 5px;
|
||||
left:0;
|
||||
}
|
||||
|
||||
.swMain .stepContainer .StepTitle {
|
||||
display:block;
|
||||
position: relative;
|
||||
margin:0;
|
||||
border:1px solid #E0E0E0;
|
||||
padding:5px;
|
||||
font: bold 16px Verdana, Arial, Helvetica, sans-serif;
|
||||
color:#5A5655;
|
||||
background-color:#E0E0E0;
|
||||
clear:both;
|
||||
text-align:left;
|
||||
z-index:88;
|
||||
-webkit-border-radius: 5px;
|
||||
-moz-border-radius : 5px;
|
||||
}
|
||||
.swMain ul.anchor {
|
||||
position: relative;
|
||||
display:block;
|
||||
float:left;
|
||||
list-style: none;
|
||||
padding: 0px;
|
||||
margin: 10px 0;
|
||||
clear: both;
|
||||
border: 0px solid #CCCCCC;
|
||||
background: transparent; /*#EEEEEE */
|
||||
}
|
||||
.swMain ul.anchor li{
|
||||
position: relative;
|
||||
display:block;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
padding-left:3px;
|
||||
padding-right: 3px;
|
||||
border: 0px solid #E0E0E0;
|
||||
float: left;
|
||||
}
|
||||
/* Anchor Element Style */
|
||||
.swMain ul.anchor li a {
|
||||
display:block;
|
||||
position:relative;
|
||||
float:left;
|
||||
margin:0;
|
||||
padding:3px;
|
||||
height:60px;
|
||||
width:230px;
|
||||
text-decoration: none;
|
||||
outline-style:none;
|
||||
-moz-border-radius : 5px;
|
||||
-webkit-border-radius: 5px;
|
||||
z-index:99;
|
||||
}
|
||||
.swMain ul.anchor li a .stepNumber{
|
||||
position:relative;
|
||||
float:left;
|
||||
width:30px;
|
||||
text-align: center;
|
||||
padding:5px;
|
||||
padding-top:0;
|
||||
font: bold 45px Verdana, Arial, Helvetica, sans-serif;
|
||||
}
|
||||
.swMain ul.anchor li a .stepDesc{
|
||||
position:relative;
|
||||
display:block;
|
||||
float:left;
|
||||
text-align: left;
|
||||
padding:5px;
|
||||
|
||||
font: bold 20px Verdana, Arial, Helvetica, sans-serif;
|
||||
}
|
||||
.swMain ul.anchor li a .stepDesc small{
|
||||
font: normal 12px Verdana, Arial, Helvetica, sans-serif;
|
||||
}
|
||||
.swMain ul.anchor li a.selected{
|
||||
color:#F8F8F8;
|
||||
background: #EA8511; /* EA8511 */
|
||||
border: 1px solid #EA8511;
|
||||
cursor:text;
|
||||
-moz-box-shadow: 5px 5px 8px #888;
|
||||
-webkit-box-shadow: 5px 5px 8px #888;
|
||||
box-shadow: 5px 5px 8px #888;
|
||||
}
|
||||
.swMain ul.anchor li a.selected:hover {
|
||||
color:#F8F8F8;
|
||||
background: #EA8511;
|
||||
}
|
||||
|
||||
.swMain ul.anchor li a.done {
|
||||
position:relative;
|
||||
color:#FFF;
|
||||
background: #8CC63F;
|
||||
border: 1px solid #8CC63F;
|
||||
z-index:99;
|
||||
}
|
||||
.swMain ul.anchor li a.done:hover {
|
||||
color:#5A5655;
|
||||
background: #8CC63F;
|
||||
border: 1px solid #5A5655;
|
||||
}
|
||||
.swMain ul.anchor li a.disabled {
|
||||
color:#CCCCCC;
|
||||
background: #F8F8F8;
|
||||
border: 1px solid #CCC;
|
||||
cursor:text;
|
||||
}
|
||||
.swMain ul.anchor li a.disabled:hover {
|
||||
color:#CCCCCC;
|
||||
background: #F8F8F8;
|
||||
}
|
||||
|
||||
.swMain ul.anchor li a.error {
|
||||
color:#6c6c6c !important;
|
||||
background: #f08f75 !important;
|
||||
border: 1px solid #fb3500 !important;
|
||||
}
|
||||
.swMain ul.anchor li a.error:hover {
|
||||
color:#000 !important;
|
||||
}
|
||||
|
||||
.swMain .buttonNext {
|
||||
display:block;
|
||||
float:right;
|
||||
margin:5px 3px 0 3px;
|
||||
padding:5px;
|
||||
text-decoration: none;
|
||||
text-align: center;
|
||||
font: bold 13px Verdana, Arial, Helvetica, sans-serif;
|
||||
width:100px;
|
||||
color:#FFF;
|
||||
outline-style:none;
|
||||
background-color: #5A5655;
|
||||
border: 1px solid #5A5655;
|
||||
-moz-border-radius : 5px;
|
||||
-webkit-border-radius: 5px;
|
||||
}
|
||||
.swMain .buttonDisabled {
|
||||
color:#F8F8F8 !important;
|
||||
background-color: #CCCCCC !important;
|
||||
border: 1px solid #CCCCCC !important;
|
||||
cursor:text;
|
||||
}
|
||||
.swMain .buttonPrevious {
|
||||
display:block;
|
||||
float:right;
|
||||
margin:5px 3px 0 3px;
|
||||
padding:5px;
|
||||
text-decoration: none;
|
||||
text-align: center;
|
||||
font: bold 13px Verdana, Arial, Helvetica, sans-serif;
|
||||
width:100px;
|
||||
color:#FFF;
|
||||
outline-style:none;
|
||||
background-color: #5A5655;
|
||||
border: 1px solid #5A5655;
|
||||
-moz-border-radius : 5px;
|
||||
-webkit-border-radius: 5px;
|
||||
}
|
||||
.swMain .buttonFinish {
|
||||
display:block;
|
||||
float:right;
|
||||
margin:5px 10px 0 3px;
|
||||
padding:5px;
|
||||
text-decoration: none;
|
||||
text-align: center;
|
||||
font: bold 13px Verdana, Arial, Helvetica, sans-serif;
|
||||
width:100px;
|
||||
color:#FFF;
|
||||
outline-style:none;
|
||||
background-color: #5A5655;
|
||||
border: 1px solid #5A5655;
|
||||
-moz-border-radius : 5px;
|
||||
-webkit-border-radius: 5px;
|
||||
}
|
||||
|
||||
/* Form Styles */
|
||||
|
||||
.txtBox {
|
||||
border:1px solid #CCCCCC;
|
||||
color:#5A5655;
|
||||
font:13px Verdana,Arial,Helvetica,sans-serif;
|
||||
padding:2px;
|
||||
width:430px;
|
||||
}
|
||||
.txtBox:focus {
|
||||
border:1px solid #EA8511;
|
||||
}
|
||||
|
||||
.swMain .loader {
|
||||
position:relative;
|
||||
display:none;
|
||||
float:left;
|
||||
margin: 2px 0 0 2px;
|
||||
padding:8px 10px 8px 40px;
|
||||
border: 1px solid #FFD700;
|
||||
font: bold 13px Verdana, Arial, Helvetica, sans-serif;
|
||||
color:#5A5655;
|
||||
background: #FFF url(loader.gif) no-repeat 5px;
|
||||
-moz-border-radius : 5px;
|
||||
-webkit-border-radius: 5px;
|
||||
z-index:998;
|
||||
}
|
||||
.swMain .msgBox {
|
||||
position:relative;
|
||||
display:none;
|
||||
float:left;
|
||||
margin: 4px 0 0 5px;
|
||||
padding:5px;
|
||||
border: 1px solid #FFD700;
|
||||
background-color: #FFFFDD;
|
||||
font: normal 12px Verdana, Arial, Helvetica, sans-serif;
|
||||
color:#5A5655;
|
||||
-moz-border-radius : 5px;
|
||||
-webkit-border-radius: 5px;
|
||||
z-index:999;
|
||||
min-width:200px;
|
||||
}
|
||||
.swMain .msgBox .content {
|
||||
font: normal 12px Verdana,Arial,Helvetica,sans-serif;
|
||||
padding: 0px;
|
||||
float:left;
|
||||
}
|
||||
.swMain .msgBox .close {
|
||||
border: 1px solid #CCC;
|
||||
border-radius: 3px;
|
||||
color: #CCC;
|
||||
display: block;
|
||||
float: right;
|
||||
margin: 0 0 0 5px;
|
||||
outline-style: none;
|
||||
padding: 0 2px 0 2px;
|
||||
position: relative;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
}
|
||||
.swMain .msgBox .close:hover{
|
||||
color: #EA8511;
|
||||
border: 1px solid #EA8511;
|
||||
}
|
||||
@@ -0,0 +1,450 @@
|
||||
/*
|
||||
* SmartWizard 3.3.1 plugin
|
||||
* jQuery Wizard control Plugin
|
||||
* by Dipu
|
||||
*
|
||||
* Refactored and extended:
|
||||
* https://github.com/mstratman/jQuery-Smart-Wizard
|
||||
*
|
||||
* Original URLs:
|
||||
* http://www.techlaboratory.net
|
||||
* http://tech-laboratory.blogspot.com
|
||||
*/
|
||||
|
||||
function SmartWizard(target, options) {
|
||||
this.target = target;
|
||||
this.options = options;
|
||||
this.curStepIdx = options.selected;
|
||||
this.steps = $(target).children("ul").children("li").children("a"); // Get all anchors
|
||||
this.contentWidth = 0;
|
||||
this.msgBox = $('<div class="msgBox"><div class="content"></div><a href="#" class="close">X</a></div>');
|
||||
this.elmStepContainer = $('<div></div>').addClass("stepContainer");
|
||||
this.loader = $('<div>Loading</div>').addClass("loader");
|
||||
this.buttons = {
|
||||
next : $('<a>'+options.labelNext+'</a>').attr("href","#").addClass("buttonNext"),
|
||||
previous : $('<a>'+options.labelPrevious+'</a>').attr("href","#").addClass("buttonPrevious"),
|
||||
finish : $('<a>'+options.labelFinish+'</a>').attr("href","#").addClass("buttonFinish")
|
||||
};
|
||||
|
||||
/*
|
||||
* Private functions
|
||||
*/
|
||||
|
||||
var _init = function($this) {
|
||||
var elmActionBar = $('<div></div>').addClass("actionBar");
|
||||
elmActionBar.append($this.msgBox);
|
||||
$('.close',$this.msgBox).click(function() {
|
||||
$this.msgBox.fadeOut("normal");
|
||||
return false;
|
||||
});
|
||||
|
||||
var allDivs = $this.target.children('div');
|
||||
$this.target.children('ul').addClass("anchor");
|
||||
allDivs.addClass("content");
|
||||
|
||||
// highlight steps with errors
|
||||
if($this.options.errorSteps && $this.options.errorSteps.length>0){
|
||||
$.each($this.options.errorSteps, function(i, n){
|
||||
$this.setError({ stepnum: n, iserror:true });
|
||||
});
|
||||
}
|
||||
|
||||
$this.elmStepContainer.append(allDivs);
|
||||
elmActionBar.append($this.loader);
|
||||
$this.target.append($this.elmStepContainer);
|
||||
elmActionBar.append($this.buttons.finish)
|
||||
.append($this.buttons.next)
|
||||
.append($this.buttons.previous);
|
||||
$this.target.append(elmActionBar);
|
||||
this.contentWidth = $this.elmStepContainer.width();
|
||||
|
||||
$($this.buttons.next).click(function() {
|
||||
$this.goForward();
|
||||
return false;
|
||||
});
|
||||
$($this.buttons.previous).click(function() {
|
||||
$this.goBackward();
|
||||
return false;
|
||||
});
|
||||
$($this.buttons.finish).click(function() {
|
||||
if(!$(this).hasClass('buttonDisabled')){
|
||||
if($.isFunction($this.options.onFinish)) {
|
||||
var context = { fromStep: $this.curStepIdx + 1 };
|
||||
if(!$this.options.onFinish.call(this,$($this.steps), context)){
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
var frm = $this.target.parents('form');
|
||||
if(frm && frm.length){
|
||||
frm.submit();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
$($this.steps).bind("click", function(e){
|
||||
if($this.steps.index(this) == $this.curStepIdx){
|
||||
return false;
|
||||
}
|
||||
var nextStepIdx = $this.steps.index(this);
|
||||
var isDone = $this.steps.eq(nextStepIdx).attr("isDone") - 0;
|
||||
if(isDone == 1){
|
||||
_loadContent($this, nextStepIdx);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
// Enable keyboard navigation
|
||||
if($this.options.keyNavigation){
|
||||
$(document).keyup(function(e){
|
||||
if(e.which==39){ // Right Arrow
|
||||
$this.goForward();
|
||||
}else if(e.which==37){ // Left Arrow
|
||||
$this.goBackward();
|
||||
}
|
||||
});
|
||||
}
|
||||
// Prepare the steps
|
||||
_prepareSteps($this);
|
||||
// Show the first slected step
|
||||
_loadContent($this, $this.curStepIdx);
|
||||
};
|
||||
|
||||
var _prepareSteps = function($this) {
|
||||
if(! $this.options.enableAllSteps){
|
||||
$($this.steps, $this.target).removeClass("selected").removeClass("done").addClass("disabled");
|
||||
$($this.steps, $this.target).attr("isDone",0);
|
||||
}else{
|
||||
$($this.steps, $this.target).removeClass("selected").removeClass("disabled").addClass("done");
|
||||
$($this.steps, $this.target).attr("isDone",1);
|
||||
}
|
||||
|
||||
$($this.steps, $this.target).each(function(i){
|
||||
$($(this).attr("href").replace(/^.+#/, '#'), $this.target).hide();
|
||||
$(this).attr("rel",i+1);
|
||||
});
|
||||
};
|
||||
|
||||
var _step = function ($this, selStep) {
|
||||
return $(
|
||||
$(selStep, $this.target).attr("href").replace(/^.+#/, '#'),
|
||||
$this.target
|
||||
);
|
||||
};
|
||||
|
||||
var _loadContent = function($this, stepIdx) {
|
||||
var selStep = $this.steps.eq(stepIdx);
|
||||
var ajaxurl = $this.options.contentURL;
|
||||
var ajaxurl_data = $this.options.contentURLData;
|
||||
var hasContent = selStep.data('hasContent');
|
||||
var stepNum = stepIdx+1;
|
||||
if (ajaxurl && ajaxurl.length>0) {
|
||||
if ($this.options.contentCache && hasContent) {
|
||||
_showStep($this, stepIdx);
|
||||
} else {
|
||||
var ajax_args = {
|
||||
url: ajaxurl,
|
||||
type: $this.options.ajaxType,
|
||||
data: ({step_number : stepNum}),
|
||||
dataType: "text",
|
||||
beforeSend: function(){
|
||||
$this.loader.show();
|
||||
},
|
||||
error: function(){
|
||||
$this.loader.hide();
|
||||
},
|
||||
success: function(res){
|
||||
$this.loader.hide();
|
||||
if(res && res.length>0){
|
||||
selStep.data('hasContent',true);
|
||||
_step($this, selStep).html(res);
|
||||
_showStep($this, stepIdx);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (ajaxurl_data) {
|
||||
ajax_args = $.extend(ajax_args, ajaxurl_data(stepNum));
|
||||
}
|
||||
$.ajax(ajax_args);
|
||||
}
|
||||
}else{
|
||||
_showStep($this,stepIdx);
|
||||
}
|
||||
};
|
||||
|
||||
var _showStep = function($this, stepIdx) {
|
||||
var selStep = $this.steps.eq(stepIdx);
|
||||
var curStep = $this.steps.eq($this.curStepIdx);
|
||||
if(stepIdx != $this.curStepIdx){
|
||||
if($.isFunction($this.options.onLeaveStep)) {
|
||||
var context = { fromStep: $this.curStepIdx+1, toStep: stepIdx+1 };
|
||||
if (! $this.options.onLeaveStep.call($this,$(curStep), context)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this.elmStepContainer.height(_step($this, selStep).outerHeight());
|
||||
var prevCurStepIdx = $this.curStepIdx;
|
||||
$this.curStepIdx = stepIdx;
|
||||
if ($this.options.transitionEffect == 'slide'){
|
||||
_step($this, curStep).slideUp("fast",function(e){
|
||||
_step($this, selStep).slideDown("fast");
|
||||
_setupStep($this,curStep,selStep);
|
||||
});
|
||||
} else if ($this.options.transitionEffect == 'fade'){
|
||||
_step($this, curStep).fadeOut("fast",function(e){
|
||||
_step($this, selStep).fadeIn("fast");
|
||||
_setupStep($this,curStep,selStep);
|
||||
});
|
||||
} else if ($this.options.transitionEffect == 'slideleft'){
|
||||
var nextElmLeft = 0;
|
||||
var nextElmLeft1 = null;
|
||||
var nextElmLeft = null;
|
||||
var curElementLeft = 0;
|
||||
if(stepIdx > prevCurStepIdx){
|
||||
nextElmLeft1 = $this.elmStepContainer.width() + 10;
|
||||
nextElmLeft2 = 0;
|
||||
curElementLeft = 0 - _step($this, curStep).outerWidth();
|
||||
} else {
|
||||
nextElmLeft1 = 0 - _step($this, selStep).outerWidth() + 20;
|
||||
nextElmLeft2 = 0;
|
||||
curElementLeft = 10 + _step($this, curStep).outerWidth();
|
||||
}
|
||||
if (stepIdx == prevCurStepIdx) {
|
||||
nextElmLeft1 = $($(selStep, $this.target).attr("href"), $this.target).outerWidth() + 20;
|
||||
nextElmLeft2 = 0;
|
||||
curElementLeft = 0 - $($(curStep, $this.target).attr("href"), $this.target).outerWidth();
|
||||
} else {
|
||||
$($(curStep, $this.target).attr("href"), $this.target).animate({left:curElementLeft},"fast",function(e){
|
||||
$($(curStep, $this.target).attr("href"), $this.target).hide();
|
||||
});
|
||||
}
|
||||
|
||||
_step($this, selStep).css("left",nextElmLeft1).show().animate({left:nextElmLeft2},"fast",function(e){
|
||||
_setupStep($this,curStep,selStep);
|
||||
});
|
||||
} else {
|
||||
_step($this, curStep).hide();
|
||||
_step($this, selStep).show();
|
||||
_setupStep($this,curStep,selStep);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
var _setupStep = function($this, curStep, selStep) {
|
||||
$(curStep, $this.target).removeClass("selected");
|
||||
$(curStep, $this.target).addClass("done");
|
||||
|
||||
$(selStep, $this.target).removeClass("disabled");
|
||||
$(selStep, $this.target).removeClass("done");
|
||||
$(selStep, $this.target).addClass("selected");
|
||||
|
||||
$(selStep, $this.target).attr("isDone",1);
|
||||
|
||||
_adjustButton($this);
|
||||
|
||||
if($.isFunction($this.options.onShowStep)) {
|
||||
var context = { fromStep: parseInt($(curStep).attr('rel')), toStep: parseInt($(selStep).attr('rel')) };
|
||||
if(! $this.options.onShowStep.call(this,$(selStep),context)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ($this.options.noForwardJumping) {
|
||||
// +2 == +1 (for index to step num) +1 (for next step)
|
||||
for (var i = $this.curStepIdx + 2; i <= $this.steps.length; i++) {
|
||||
$this.disableStep(i);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var _adjustButton = function($this) {
|
||||
if (! $this.options.cycleSteps){
|
||||
if (0 >= $this.curStepIdx) {
|
||||
$($this.buttons.previous).addClass("buttonDisabled");
|
||||
if ($this.options.hideButtonsOnDisabled) {
|
||||
$($this.buttons.previous).hide();
|
||||
}
|
||||
}else{
|
||||
$($this.buttons.previous).removeClass("buttonDisabled");
|
||||
if ($this.options.hideButtonsOnDisabled) {
|
||||
$($this.buttons.previous).show();
|
||||
}
|
||||
}
|
||||
if (($this.steps.length-1) <= $this.curStepIdx){
|
||||
$($this.buttons.next).addClass("buttonDisabled");
|
||||
if ($this.options.hideButtonsOnDisabled) {
|
||||
$($this.buttons.next).hide();
|
||||
}
|
||||
}else{
|
||||
$($this.buttons.next).removeClass("buttonDisabled");
|
||||
if ($this.options.hideButtonsOnDisabled) {
|
||||
$($this.buttons.next).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Finish Button
|
||||
if (! $this.steps.hasClass('disabled') || $this.options.enableFinishButton){
|
||||
$($this.buttons.finish).removeClass("buttonDisabled");
|
||||
if ($this.options.hideButtonsOnDisabled) {
|
||||
$($this.buttons.finish).show();
|
||||
}
|
||||
}else{
|
||||
$($this.buttons.finish).addClass("buttonDisabled");
|
||||
if ($this.options.hideButtonsOnDisabled) {
|
||||
$($this.buttons.finish).hide();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Public methods
|
||||
*/
|
||||
|
||||
SmartWizard.prototype.goForward = function(){
|
||||
var nextStepIdx = this.curStepIdx + 1;
|
||||
if (this.steps.length <= nextStepIdx){
|
||||
if (! this.options.cycleSteps){
|
||||
return false;
|
||||
}
|
||||
nextStepIdx = 0;
|
||||
}
|
||||
_loadContent(this, nextStepIdx);
|
||||
};
|
||||
|
||||
SmartWizard.prototype.goBackward = function(){
|
||||
var nextStepIdx = this.curStepIdx-1;
|
||||
if (0 > nextStepIdx){
|
||||
if (! this.options.cycleSteps){
|
||||
return false;
|
||||
}
|
||||
nextStepIdx = this.steps.length - 1;
|
||||
}
|
||||
_loadContent(this, nextStepIdx);
|
||||
};
|
||||
|
||||
SmartWizard.prototype.goToStep = function(stepNum){
|
||||
var stepIdx = stepNum - 1;
|
||||
if (stepIdx >= 0 && stepIdx < this.steps.length) {
|
||||
_loadContent(this, stepIdx);
|
||||
}
|
||||
};
|
||||
SmartWizard.prototype.enableStep = function(stepNum) {
|
||||
var stepIdx = stepNum - 1;
|
||||
if (stepIdx == this.curStepIdx || stepIdx < 0 || stepIdx >= this.steps.length) {
|
||||
return false;
|
||||
}
|
||||
var step = this.steps.eq(stepIdx);
|
||||
$(step, this.target).attr("isDone",1);
|
||||
$(step, this.target).removeClass("disabled").removeClass("selected").addClass("done");
|
||||
}
|
||||
SmartWizard.prototype.disableStep = function(stepNum) {
|
||||
var stepIdx = stepNum - 1;
|
||||
if (stepIdx == this.curStepIdx || stepIdx < 0 || stepIdx >= this.steps.length) {
|
||||
return false;
|
||||
}
|
||||
var step = this.steps.eq(stepIdx);
|
||||
$(step, this.target).attr("isDone",0);
|
||||
$(step, this.target).removeClass("done").removeClass("selected").addClass("disabled");
|
||||
}
|
||||
SmartWizard.prototype.currentStep = function() {
|
||||
return this.curStepIdx + 1;
|
||||
}
|
||||
|
||||
SmartWizard.prototype.showMessage = function (msg) {
|
||||
$('.content', this.msgBox).html(msg);
|
||||
this.msgBox.show();
|
||||
}
|
||||
SmartWizard.prototype.hideMessage = function () {
|
||||
this.msgBox.fadeOut("normal");
|
||||
}
|
||||
SmartWizard.prototype.showError = function(stepnum) {
|
||||
this.setError(stepnum, true);
|
||||
}
|
||||
SmartWizard.prototype.hideError = function(stepnum) {
|
||||
this.setError(stepnum, false);
|
||||
}
|
||||
SmartWizard.prototype.setError = function(stepnum,iserror) {
|
||||
if (typeof stepnum == "object") {
|
||||
iserror = stepnum.iserror;
|
||||
stepnum = stepnum.stepnum;
|
||||
}
|
||||
|
||||
if (iserror){
|
||||
$(this.steps.eq(stepnum-1), this.target).addClass('error')
|
||||
}else{
|
||||
$(this.steps.eq(stepnum-1), this.target).removeClass("error");
|
||||
}
|
||||
}
|
||||
|
||||
SmartWizard.prototype.fixHeight = function(){
|
||||
var height = 0;
|
||||
|
||||
var selStep = this.steps.eq(this.curStepIdx);
|
||||
var stepContainer = _step(this, selStep);
|
||||
stepContainer.children().each(function() {
|
||||
height += $(this).outerHeight();
|
||||
});
|
||||
|
||||
// These values (5 and 20) are experimentally chosen.
|
||||
stepContainer.height(height + 5);
|
||||
this.elmStepContainer.height(height + 20);
|
||||
}
|
||||
|
||||
_init(this);
|
||||
};
|
||||
|
||||
|
||||
|
||||
(function($){
|
||||
|
||||
$.fn.smartWizard = function(method) {
|
||||
var args = arguments;
|
||||
var rv = undefined;
|
||||
var allObjs = this.each(function() {
|
||||
var wiz = $(this).data('smartWizard');
|
||||
if (typeof method == 'object' || ! method || ! wiz) {
|
||||
var options = $.extend({}, $.fn.smartWizard.defaults, method || {});
|
||||
if (! wiz) {
|
||||
wiz = new SmartWizard($(this), options);
|
||||
$(this).data('smartWizard', wiz);
|
||||
}
|
||||
} else {
|
||||
if (typeof SmartWizard.prototype[method] == "function") {
|
||||
rv = SmartWizard.prototype[method].apply(wiz, Array.prototype.slice.call(args, 1));
|
||||
return rv;
|
||||
} else {
|
||||
$.error('Method ' + method + ' does not exist on jQuery.smartWizard');
|
||||
}
|
||||
}
|
||||
});
|
||||
if (rv === undefined) {
|
||||
return allObjs;
|
||||
} else {
|
||||
return rv;
|
||||
}
|
||||
};
|
||||
|
||||
// Default Properties and Events
|
||||
$.fn.smartWizard.defaults = {
|
||||
selected: 0, // Selected Step, 0 = first step
|
||||
keyNavigation: true, // Enable/Disable key navigation(left and right keys are used if enabled)
|
||||
enableAllSteps: false,
|
||||
transitionEffect: 'fade', // Effect on navigation, none/fade/slide/slideleft
|
||||
contentURL:null, // content url, Enables Ajax content loading
|
||||
contentCache:true, // cache step contents, if false content is fetched always from ajax url
|
||||
cycleSteps: false, // cycle step navigation
|
||||
enableFinishButton: false, // make finish button enabled always
|
||||
hideButtonsOnDisabled: false, // when the previous/next/finish buttons are disabled, hide them instead?
|
||||
errorSteps:[], // Array Steps with errors
|
||||
labelNext:'Next',
|
||||
labelPrevious:'Previous',
|
||||
labelFinish:'Finish',
|
||||
noForwardJumping: false,
|
||||
ajaxType: "POST",
|
||||
onLeaveStep: null, // triggers when leaving a step
|
||||
onShowStep: null, // triggers when showing a step
|
||||
onFinish: null // triggers when Finish button is clicked
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.7 KiB |
Reference in New Issue
Block a user