Skip to content

Instantly share code, notes, and snippets.

@raihan-uddin
Created August 27, 2019 04:09
Show Gist options
  • Save raihan-uddin/792d25cc2c208518c2c41ecbc8d76f8d to your computer and use it in GitHub Desktop.
Save raihan-uddin/792d25cc2c208518c2c41ecbc8d76f8d to your computer and use it in GitHub Desktop.
Yii
//Form submit
//form submit prevent default jquery based on condition
$("#submit").click(function(event) {
var deliveryDate = $("#Csd_delivery_date").val();
if (deliveryDate == "") {
alertify.alert('Please Select Delivery Date!');
event.preventDefault();
}
});
$('input, :input').attr('autocomplete', 'off');
$(".reportTab tbody tr:even").css("background-color","rgb(192,192,192, 0.1)");
// rgba equivalent for yellow with 50% opacity
$(".reportTab tbody tr:odd").css("background-color","rgba(255,255,0,0.1)");
/// reload after voucher preview
<script>
$(function(){
$(".ui-icon-closethick").click(function(){
window.location.href = "<?php echo Yii::app()->baseUrl; ?>/supply_chain/csd/adminReturned/";
});
});
</script>
// ajax response
var salePriceData = $.parseJSON($.ajax({
url: '<?php echo Yii::app()->createAbsoluteUrl('inventory/prodModels/jquery_showSellPrice') ?>',
data: {prod_id: model_id, cash_credit: cash_due},
dataType: "json",
cache: false,
type: "POST",
async: false
}).responseText); // This will wait until you get a response from the ajax request.
// Now you can use data.posX, data.posY later in your code and it will work.
//console.log(salePriceData);
//Controller:
$this->pageTitle = 'Suppliers';
///View
<?php $this->widget('application.components.BreadCrumb', array(
'crumbs' => array(
array('name' => 'Store & Inventory', 'url' => array('')),
array('name' => 'Products and Items Config', 'url' => array('')),
array('name' => 'Suppliers',),
),
// 'delimiter' => ' &rarr; ',
)); ?>
Ajax submit:
$.ajax({
url: url,
type: 'post',
dataType: 'json',
data: data,
beforeSend: function () {
disableEnableButton("save", true);
var check = 0;
$("input.styles").each(function () {
var qty = parseInt($(this).val());
if (isNaN(qty))
qty = 0;
if (qty == 0) {
check++;
$(this).css({"border-color": "red"});
} else {
$(this).css({"border-color": ""});
}
});
if (check > 0) {
alertify.alert('Warning', '<i class="fa fa-warning warning"> At least Add One Product To Grid!</i>', function () {
alertify.warning('Error!');
});
event.preventDefault();
}
},
error: function (xhr) { // if error occured
disableEnableButton("save", false);
alertify.warning("Error occured.please try again");
alertify.warning(xhr.statusText + xhr.responseText);
},
}).done(function (response) {
disableEnableButton("save", false);
if (response.data.success == true) {
alert("Saved");
}
}).fail(function () {
console.log("error");
});
return [
'data' => [
'success' => true,
'model' => $model,
'message' => 'Model has been saved.',
],
'code' => 0,
];
return [
'data' => [
'success' => false,
'model' => null,
'message' => 'An error occured.',
],
'code' => 1, // Some semantic codes that you know them for yourself
];
// register css & js in veiw
$this->registerJsFile(
'@web/js/alertify.min.js',
['depends' => [\yii\web\JqueryAsset::className()]]
);
$this->registerCssFile("@web/css/alertify.min.css", [
'depends' => [\yii\bootstrap\BootstrapAsset::className()],
'media' => 'print',
], 'css-print-theme');
$this->registerCssFile("@web/css/default.min.css", [
'depends' => [\yii\bootstrap\BootstrapAsset::className()],
'media' => 'print',
], 'css-print-theme');
$this->registerCssFile("@web/css/semantic.min.css", [
'depends' => [\yii\bootstrap\BootstrapAsset::className()],
'media' => 'print',
], 'css-print-theme');
$this->registerCssFile("@web/css/bootstrap.min.css", [
'depends' => [\yii\bootstrap\BootstrapAsset::className()],
'media' => 'print',
], 'css-print-theme');
$this->registerCssFile("@web/css/bootstrap.min.css", ['depends' => [\yii\bootstrap\BootstrapAsset::className()]]);
//gridview datepicker
search filter datepicker
[
'attribute' => 'issue_date',
'content' => function ($model, $key, $index, $column) {
return Yii::$app->formatter->asDate($model->issue_date);
},
'filterType'=> \kartik\grid\GridView::FILTER_DATE,
'filterWidgetOptions' => [
'options' => ['placeholder' => 'Select date'],
'pluginOptions' => [
'format' => 'yyyy-mm-dd',
'todayHighlight' => true
]
],
'group' => true,
'format' => 'html',
'width' => '8%',
],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment