first commit
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
|
||||
jQuery(function () {
|
||||
jQuery('#icl-migrate-start').one('click', function () {
|
||||
iclStepper(jQuery(this).attr('href'), '&init=1', true);
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
function iclStepper(href, addUrl, init) {
|
||||
init = typeof(init) != 'undefined' ? true : false;
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: href+addUrl,
|
||||
cache: false,
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
if (data.stop == true) {
|
||||
jQuery('#icl-migrate-progress .message').html('stopped');
|
||||
} else if (data.error == false) {
|
||||
if (init == true) {
|
||||
jQuery('#icl-migrate-start').fadeOut(function(){
|
||||
jQuery('#icl-migrate-progress').fadeIn().html(data.output).children('.message').html(data.message);
|
||||
iclStepper(href, '&step='+data.step);
|
||||
});
|
||||
// jQuery('#icl-migrate-progress').html(data.output).children('.message').html(data.message);
|
||||
} else {
|
||||
jQuery('#icl-migrate-progress .message').html(data.message);
|
||||
jQuery('#icl-migrate-progress .progress').animate({
|
||||
width : data.barWidth+'%'
|
||||
}, 100);
|
||||
if (data.completed == true) {
|
||||
jQuery('#icl-migrate').delay(3000).fadeOut();
|
||||
} else {
|
||||
iclStepper(href, '&step='+data.step);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alert('error');
|
||||
jQuery('#icl-migrate-progress .message').html(data.error);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
class Icl_Stepper {
|
||||
|
||||
|
||||
/**
|
||||
* Added dummy element to match number of elements and to cover init action
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_steps = array( null );
|
||||
/**
|
||||
* Current step
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_step;
|
||||
/**
|
||||
* Next step can be forced with Icl_Stepper::setNextStep()
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_nextStep = null;
|
||||
|
||||
/**
|
||||
* Provide current step here
|
||||
*
|
||||
* @param int $step
|
||||
*/
|
||||
function __construct( $step = 0 ) {
|
||||
if ( empty( $step ) ) {
|
||||
$step = 0;
|
||||
}
|
||||
$this->_step = intval( $step );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register steps (function names)
|
||||
*/
|
||||
public function registerSteps() {
|
||||
$args = func_get_args();
|
||||
$this->_steps = array_merge( $this->_steps, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current step
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getStep() {
|
||||
return $this->_step;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns next step
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNextStep() {
|
||||
return ! is_null( $this->_nextStep ) ? $this->_nextStep : $this->_step += 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets current step
|
||||
*
|
||||
* @param int $num
|
||||
*/
|
||||
public function setStep( $num ) {
|
||||
$this->_step = intval( $num );
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcing next step
|
||||
*
|
||||
* @param int $num
|
||||
*/
|
||||
public function setNextStep( $num ) {
|
||||
$this->_nextStep = intval( $num );
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates bar width
|
||||
*
|
||||
* @return int Should be used as percentage width (%)
|
||||
*/
|
||||
public function barWidth() {
|
||||
return round( ( $this->_step * 100 ) / count( $this->_steps ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls current step's function
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function init() {
|
||||
if ( $this->_step !== 0 && isset( $this->_steps[ $this->_step ] )
|
||||
&& is_callable( $this->_steps[ $this->_step ] ) ) {
|
||||
return call_user_func_array( $this->_steps[ $this->_step ], array( $this->_step, $this ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns initial HTML formatted screen
|
||||
*
|
||||
* @param string $message Message to be displayed
|
||||
* @return string
|
||||
*/
|
||||
public function render( $message = '' ) {
|
||||
$output = '<div class="progress-bar" style="width: 100%; height: 15px; background-color: #FFFFFFF; border: 1px solid #e6db55;">
|
||||
<div class="progress" style="height: 100%; background-color: Yellow; width: ' . $this->barWidth() . '%;"></div>
|
||||
</div>
|
||||
<div class="message" style="clear:both;">' . $message . '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user