Created
September 18, 2015 12:00
-
-
Save maximishchenko/50e9a0e44b3fe53b9eff to your computer and use it in GitHub Desktop.
Yii add ajax loading indicator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$this->widget('bootstrap.widgets.TbButton', array( | |
'label'=>'<ButtonName>', | |
'type'=>'ButtonType', | |
'buttonType'=>'ajaxButton', | |
'encodeLabel'=>true, | |
'url'=>Yii::app()->createUrl('/<module>/<controller>/<action>'), | |
'ajaxOptions'=>array( | |
// Method - POST (for $_POST requests) or GET (for $_GET requests) | |
'type'=>'<method>', | |
// Data - that be send by ajax to controller action | |
"data" => "<data>", | |
// Selector for update | |
'update'=>'#selector', | |
// Function that be executed after ajax success | |
'success' => "<success_function>", | |
// Add loading class Before send ajax-request | |
'beforeSend' => 'function(){ | |
$("#<selector_loading>").addClass("ajax_loading"); | |
}', | |
'complete' => 'function(){ | |
$("#selector_loading").removeClass("ajax_loading"); | |
}', | |
), | |
'htmlOptions' => array( | |
'onclick' => ' | |
var id_list_lock=$.fn.yiiGridView.getSelection("company-grid","ids"); | |
if (id_list_lock=="") { | |
alert("Нет отмеченных записей!", "Alert Dialog"); | |
}', | |
'confirm' => 'Удалить выбранные записи?', | |
), | |
'type'=>null, | |
'size'=>'small', | |
)); | |
// Also Need sleep(time_seconds); at the begin of controller/action | |
?> | |
<!-- CSS-styles --> | |
div.loading { | |
background-color: #eee; | |
background-image: url('loading.gif'); | |
background-position: center center; | |
background-repeat: no-repeat; | |
opacity: 1; | |
} | |
div.loading * { | |
opacity: .8; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment