/** * @param $item * @return string */ public static function settingField($key, $item, $traslateCategory) { $return = ''; switch ($item['type']) { case 'checkbox': $return = parent::beginTag('div', ['class' => 'form-group']) . parent::beginTag('label', ['class' => 'col-md-3 control-label']) . \Yii::t($traslateCategory, $key) . parent::endTag('label') . parent::beginTag('div', ['class' => 'col-md-9']) . parent::hiddenInput('Settings[' . $key . ']', 0) . \oakcms\bootstrapswitch\Switcher::widget(['id' => 'wid' . uniqid(), 'name' => 'Settings[' . $key . ']', 'checked' => $item['value']]) . parent::endTag('div') . parent::endTag('div'); break; case 'textInput': $return = parent::beginTag('div', ['class' => 'form-group']) . parent::beginTag('label', ['class' => 'col-md-3 control-label']) . \Yii::t($traslateCategory, $key) . parent::endTag('label') . parent::beginTag('div', ['class' => 'col-md-9']) . parent::textInput('Settings[' . $key . ']', $item['value'], ['class' => 'form-control']) . parent::endTag('div') . parent::endTag('div'); break; case 'textarea': $return = parent::beginTag('div', ['class' => 'form-group']) . parent::beginTag('label', ['class' => 'col-md-3 control-label']) . \Yii::t($traslateCategory, $key) . parent::endTag('label') . parent::beginTag('div', ['class' => 'col-md-9']) . parent::textarea('Settings[' . $key . ']', $item['value'], ['class' => 'form-control']) . parent::endTag('div') . parent::endTag('div'); break; case 'mediaInput': $return = parent::beginTag('div', ['class' => 'form-group']) . parent::beginTag('label', ['class' => 'col-md-3 control-label']) . \Yii::t($traslateCategory, $key) . parent::endTag('label') . parent::beginTag('div', ['class' => 'col-md-9']) . InputFile::widget(['id' => 'wid' . uniqid(), 'language' => \Yii::$app->language, 'filter' => 'image', 'name' => 'Settings[' . $key . ']', 'value' => $item['value']]) . parent::endTag('div') . parent::endTag('div'); break; default: $return = ''; break; } return $return; }
private function registerAssets() { GalleryAssets::register($this->getView()); $this->getView()->registerJs(' function insertImagePath(element){ var data = $("#let_galleries").val(); if (data == ""){ $("#let_galleries").val($(element).attr("id")); } else { $("#let_galleries").val(data.concat("," + $(element).attr("id"))); } } function addImageByGallery(type){ var module = "' . $this->moduleName . '", columns = \'' . \yii\helpers\Json::encode($this->columns) . '\', image = $("#image").val(); $.ajax({ url: "' . \yii\helpers\Url::to(['/gallery/ajax/additemimage']) . '", type: "post", data: {type: type, module: module, columns: columns, image: image}, }).done(function (data) { if (data.length > 0) { $("#tableImage").append(data); $("#sya_gallery").modal("hide"); } }); } // Ham xoa anh function removeImage(element){ var confirmAlert = confirm("' . Yii::t('yii', 'Are you sure you want to delete this item?') . '"); if (confirmAlert == true){ $(element).parents("#imageItem").remove(); // Kiem tra co anh trong gallery hay khong if ($("#tableImage").children().length == 0) { $("#tableImage").append(\'' . Html::hiddenInput($this->moduleName . '[gallery]', '', ['class' => 'form-control']) . '\'); } } } ', \yii\web\View::POS_END); $this->getView()->registerJs(' // Sap xep anh $("#tableImage").sortable({}); // Dropzone drop and drag file Dropzone.options.myAwesomeDropzone = { uploadMultiple: true, parallelUploads: 100, maxFiles: 100, paramName: "image", params: { type: "' . self::TYPE_UPLOAD . '", module: "' . $this->moduleName . '", columns: \'' . \yii\helpers\Json::encode($this->columns) . '\' }, autoDiscover: false, url: "' . \yii\helpers\Url::to(['/gallery/ajax/additemimage']) . '", headers: { "Accept": "*/*", "' . \yii\web\Request::CSRF_HEADER . '": "' . Yii::$app->getRequest()->csrfToken . '", "Access-Control-Allow-Origin": "*" }, // Dropzone settings init: function() { this.on("sendingmultiple", function(image, xhr, formData) { formData.processData = false; formData.contentType = false; formData.enctype = "multipart/form-data"; }); this.on("successmultiple", function(files, responseText, e) { $("#tableImage").append(responseText); }); } } // Forcus input $(".custom_modal_gallery a[data-toggle=\'tab\']").on("shown.bs.tab", function (e) { $("#insert_image").attr("data-type", $(e.target).attr("data-type")); $(e.target).parents(".tabs-container").find("#image").focus(); }) $("#image").on("input",function(e){ $.ajax({ url: "' . \yii\helpers\Url::to(['/gallery/ajax/getimagepreview']) . '", type: "post", data: {image: $(this).val()}, }).done(function (data) { $("#embed_url_settings").html(data); }); }); $("#insert_image").click(function() { addImageByGallery($(this).attr("data-type")); }); ', yii\web\View::POS_READY); }
/** * Function generate list product order * @param array $products list product [ * 1 => [ * 'id' => 1, * 'sku' => '123', * 'title' => 'sdsd', * 'price' => 50000, * 'quantity' => 1, * 'is_marketing' => '1', * ] * ] * @return string */ public function generateProductOrder($products = [], $shipping = 0) { if (!empty($products)) { // IF shipping is not number then assign value shipping = 0 if (!is_integer(intval($shipping))) { $shipping = 0; } // Get model name of product $ecommerce = Ecommerce::module(); $modelName = end(explode('\\', $ecommerce->itemModule)); $columnProduct = ArrayHelper::getValue($ecommerce->productTable, 'fieldOrder'); // Begin list product order $template = Html::beginTag('div', ['class' => 'table-responsive']); $template .= Html::beginTag('table', ['class' => 'table table-striped']); // Begin header table $template .= Html::beginTag('thead'); $template .= Html::beginTag('tr'); $template .= Html::beginTag('th'); $template .= Yii::t('ecommerce', 'ID'); $template .= Html::endTag('th'); foreach ($columnProduct as $column => $item) { $template .= Html::beginTag('th'); $template .= Yii::t('ecommerce', ucfirst($column)); $template .= Html::endTag('th'); } $template .= Html::beginTag('th'); $template .= Yii::t('ecommerce', 'Quantity'); $template .= Html::endTag('th'); $template .= Html::beginTag('th', ['colspan' => 2]); $template .= Yii::t('ecommerce', 'Total Price'); $template .= Html::endTag('th'); if ($ecommerce->enableActivitionCode) { $template .= Html::beginTag('th'); $template .= Yii::t('ecommerce', 'Activation Code'); $template .= Html::endTag('th'); } $template .= Html::endTag('tr'); $template .= Html::endTag('thead'); // End header table // Begin list product $template .= Html::beginTag('tbody'); $sumTotal = 0; foreach ($products as $product) { // Get value in product $id = ArrayHelper::getValue($product, 'id', ''); $sku = ArrayHelper::getValue($product, 'sku', ''); $title = ArrayHelper::getValue($product, 'title', ''); $price = ArrayHelper::getValue($product, 'price', 0); $quantity = ArrayHelper::getValue($product, 'quantity', 1); $is_marketing = ArrayHelper::getValue($product, 'is_marketing', '1'); $activationCode = ActivationCode::find()->select(['code'])->where(['product_id' => $id, 'order_id' => Yii::$app->request->get('id')])->one(); $total = $price * $quantity; $sumTotal += $total; $template .= Html::beginTag('tr'); $template .= Html::beginTag('td', ['class' => 'text-vertical']); $template .= Html::tag('span', $id, ['class' => 'product_id']); $template .= Html::hiddenInput($modelName . '[product][' . $id . '][id]', $id, ['class' => 'form-control', 'readonly' => true]); $template .= Html::endTag('td'); foreach ($columnProduct as $column => $item) { $template .= Html::beginTag('td', ['class' => 'text-vertical']); $value = $valueColumn = ArrayHelper::getValue($product, $column, ''); if ('price' == $column) { $value = ArrayHelper::getValue($product, $column, 0); $valueColumn = Yii::$app->formatter->asDecimal($value, 0) . ' VNĐ'; } $template .= $valueColumn; $template .= Html::hiddenInput($modelName . '[product][' . $id . '][' . $column . ']', $value, ['class' => 'form-control', 'readonly' => true]); $template .= Html::endTag('td'); } $template .= Html::beginTag('td', ['style' => 'width: 5%;']); if ($ecommerce->multiple) { $template .= Html::textInput($modelName . '[product][' . $id . '][quantity]', $quantity, ['class' => 'form-control product_qty text-center', 'onkeyup' => 'return totalPriceProduct(this);']); } else { $template .= $quantity; $template .= Html::hiddenInput($modelName . '[product][' . $id . '][quantity]', $quantity, ['class' => 'form-control product_qty text-center', 'onkeyup' => 'return totalPriceProduct(this);']); } $template .= Html::endTag('td'); $template .= Html::beginTag('td', ['class' => 'text-vertical', 'colspan' => 2]); $template .= Html::tag('span', Yii::$app->formatter->asDecimal($total, 0) . ' VNĐ', ['class' => 'product_total', 'data-total' => $total]); $template .= Html::endTag('td'); if ($ecommerce->enableActivitionCode) { $template .= Html::beginTag('td', ['class' => 'text-vertical']); $template .= ArrayHelper::getValue($activationCode, 'code', null); $template .= Html::endTag('td'); } $template .= Html::endTag('tr'); } $colspan = count($columnProduct) + 3; if (!$ecommerce->enableActivitionCode) { $colspan = count($columnProduct) + 2; } // Begin shipping $template .= Html::beginTag('tr'); $template .= Html::beginTag('td', ['colspan' => $colspan, 'class' => 'text-right', 'style' => 'vertical-align: middle;']); $template .= Yii::t('ecommerce', 'Shipping') . ': '; $template .= Html::endTag('td'); $template .= Html::beginTag('td', ['width' => '100px']); $template .= Html::textInput('shipping', Yii::$app->formatter->asDecimal($shipping, 0), ['class' => 'form-control pull-left', 'onkeyup' => 'return addShipping(this);']); $template .= Html::hiddenInput($modelName . '[shipping]', $shipping, ['id' => 'syaShipping', 'class' => 'form-control product_total', 'readonly' => true, 'data-total' => $shipping]); $template .= Html::endTag('td'); $template .= Html::beginTag('td', ['style' => 'vertical-align: middle;']); $template .= ' VNĐ'; $template .= Html::endTag('td'); $template .= Html::endTag('tr'); // End shipping // Begin total product $template .= Html::beginTag('tr'); $template .= Html::beginTag('td', ['colspan' => $colspan, 'class' => 'text-right']); $template .= Yii::t('ecommerce', 'Total') . ': '; $template .= Html::endTag('td'); $template .= Html::beginTag('td', ['colspan' => '2']); $template .= Html::tag('span', Yii::$app->formatter->asDecimal($sumTotal + $shipping, 0), ['id' => 'product_total']) . ' VNĐ'; $template .= Html::endTag('td'); $template .= Html::endTag('tr'); // End total product $template .= Html::endTag('tbody'); // End list product $template .= Html::endTag('table'); // End list product order $template .= Html::endTag('div'); // End table-responsive return $template; } return null; }
<div class="col-sm-5"> </div> <div class="col-sm-3"> <?php echo $form->field($model, 'repetir_val')->textInput(['placeholder' => 'Valor']); ?> </div> <div class="col-sm-4"> <?php echo $form->field($model, 'repetir_termina')->textInput(['placeholder' => 'Data']); ?> </div> </div> <?php echo \yii\bootstrap\Html::hiddenInput('Atividades[condicional_dia_util]', 0); ?> <?php echo $form->field($model, 'condicional_dia_util')->dropDownList(Yii::$app->params['condicional_dia_util']); ?> <?php echo $form->field($model, 'procedimento')->textarea(['rows' => 6]); ?> <div class="form-group field-atividades-procedimento"> <label class="control-label col-md-5" for="atividades-procedimento">Anexos</label> <div class="col-md-7"> <input type="file" id="atividades-anexos" name="Atividades[anexos][]"> </div> <div class="col-md-offset-5 col-md-7"></div> <div class="col-md-offset-5 col-md-7"><div class="help-block"></div></div> </div>
<div class="row m-b-sm"> <div class="col-lg-12"> <div id="msg" style="display: none;" class="alert alert-dismissable"></div> <?php if (!empty($role)) { echo Html::buttonInput(Yii::t('common', 'Save'), ['class' => 'btn btn-primary m-r-md', 'onclick' => 'addPermissionFromRole();']); } echo Html::dropDownList('choseRole', $role, ArrayHelper::map($auth->getRoles(), 'name', 'description'), ['prompt' => Yii::t('account', 'Select a role'), 'class' => 'chosen-select', 'id' => 'role', 'onchange' => 'changeUrlPermission()']); ?> </div> </div> <div id="message"></div> <?php if (!empty($role)) { echo Html::hiddenInput('allPermission', implode(',', \app\helpers\ArrayHelper::map($dataProvider->getModels(), '_id', 'name')), ['id' => 'allPermission']); echo GridView::widget(['panel' => ['heading' => Yii::t(Yii::$app->controller->module->id, 'Account'), 'tableOptions' => ['id' => 'listDefault']], 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'app\\modules\\account\\components\\SelectPermissionForRoleColumn'], 'name', 'description', 'rule_name'], 'responsive' => true, 'hover' => true]); } ?> </div> <script type="text/javascript"> function addPermissionFromRole() { var ids = $('input[name="selection[]"]:checked').serialize(); var choseRole = $('#role option:selected').val(); var allpermission = $('#allPermission').val(); $.ajax({ type: "POST", dataType: "json", url: "<?php
<div class="row"> <div class="col-lg-12"> <div class="ibox float-e-margins"> <div class="ibox-title"> <h5><?php echo Yii::t('common', 'Information'); ?> </h5> </div> <div class="ibox-content"> <?php $form = ActiveForm::begin(['id' => 'formDefault', 'layout' => 'horizontal', 'options' => ['enctype' => 'multipart/form-data'], 'fieldConfig' => ['horizontalCssClasses' => ['label' => 'col-sm-2', 'wrapper' => 'col-sm-10', 'error' => 'help-block m-b-none', 'hint' => '']]]); // Image $imageConfig = ['options' => ['accept' => 'uploads/*'], 'pluginOptions' => ['previewFileType' => 'image', 'showCaption' => FALSE, 'showRemove' => FALSE, 'showUpload' => FALSE, 'browseClass' => 'btn btn-primary btn-block', 'browseIcon' => '<i class="glyphicon glyphicon-camera"></i> ', 'browseLabel' => 'Select Photo', 'removeClass' => 'btn btn-danger', 'removeLabel' => "Delete", 'removeIcon' => '<i class="glyphicon glyphicon-trash"></i>', 'allowedFileExtensions' => ['jpg', 'gif', 'png', 'jpeg']]]; if (!empty($model->image)) { $imageConfig['pluginOptions']['initialPreview'] = [Html::img(LetHelper::getFileUploaded($model->image), ['class' => 'file-preview-image'])]; } // END Image $tabs = [['label' => Yii::t('common', 'General information'), 'content' => $form->field($model, 'name')->textInput() . $form->field($model, 'class')->textInput() . $form->field($model, 'skin')->textInput() . $form->field($model, 'image')->widget(FileInput::classname(), $imageConfig) . $form->field($model, 'content')->widget(letyii\tinymce\Tinymce::className(), ['options' => ['style' => 'height: 400px;'], 'configs' => ['plugins' => 'moxiemanager advlist autolink lists link image charmap print preview hr anchor pagebreak ' . 'searchreplace wordcount visualblocks visualchars code fullscreen ' . 'insertdatetime media nonbreaking save table contextmenu directionality ' . 'emoticons template paste textcolor colorpicker textpattern', 'toolbar1' => 'insertfile undo redo | styleselect | fontselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image', 'toolbar2' => 'print preview media | forecolor backcolor emoticons', 'moxiemanager_image_settings' => ['moxiemanager_title' => 'Images', 'moxiemanager_extensions' => 'jpg,png,gif', 'moxiemanager_rootpath' => '/uploads/editor', 'moxiemanager_view' => 'thumbs'], 'external_plugins' => ['moxiemanager' => Url::base() . '/plugins/moxiemanager/plugin.min.js'], 'entity_encoding' => 'raw', 'force_p_newlines' => true, 'force_br_newlines' => false, 'auto_cleanup_word' => false, 'relative_urls' => true, 'convert_urls' => false, 'remove_script_host' => true, 'verify_html' => false, 'forced_root_block' => false, 'content_css' => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css', 'templates' => Url::to(['template'])]]) . $form->field($model, 'description')->textarea() . $form->field($model, 'promotion')->widget(SwitchInput::className(['type' => SwitchInput::RADIO])) . $form->field($model, 'status')->widget(SwitchInput::className(['type' => SwitchInput::RADIO])), 'active' => true], ['label' => 'Seo', 'content' => $form->field($model, 'slug')->textInput() . $form->field($model, 'slug_prefix')->textInput() . $form->field($model, 'seo_url')->textInput() . $form->field($model, 'seo_title')->textInput() . $form->field($model, 'seo_desc')->textInput(), $form->field($model, 'seo_keyword')->textInput()]]; echo Html::hiddenInput('save_type', 'save'); echo yii\bootstrap\Tabs::widget(['items' => $tabs]); ActiveForm::end(); ?> </div> </div> </div> </div> </div>
<div class="box-body"> <?php echo GridView::widget(['dataProvider' => $transferDataProvider, 'tableOptions' => ['class' => 'table table-hover'], 'layout' => "{items}\n{pager}", 'rowOptions' => function ($model) { return ['class' => $model->hasErrors('password') ? 'danger' : '']; }, 'columns' => [['attribute' => 'domain', 'format' => 'raw', 'value' => function ($model, $key, $i) { $html = Html::tag('span', $model->domain, ['class' => 'text-bold']); /** @var Domain $model */ if (!$model->hasErrors('password')) { $html .= Html::hiddenInput("DomainTransferProduct[{$i}][name]", $model->domain); } return $html; }], ['attribute' => 'password', 'format' => 'raw', 'value' => function ($model, $key, $i) { $html = $model->password; /** @var Domain $model */ if (!$model->hasErrors('password')) { $html .= Html::hiddenInput("DomainTransferProduct[{$i}][password]", $model->password); } return $html; }], ['label' => Yii::t('hipanel:domain', 'Additional message'), 'value' => function ($model) { /* @var Domain $model */ return $model->hasErrors('password') ? $model->getFirstError('password') : ''; }]]]); ?> </div> <div class="box-footer"> <?php echo Html::submitButton('<i class="fa fa-shopping-cart"></i> ' . Yii::t('hipanel:domain', 'Add to cart'), ['class' => 'btn btn-success']); ?> <?php echo Html::a(Yii::t('hipanel:domain', 'Return to transfer form'), ['transfer'], ['class' => 'btn btn-default']); ?>
<div id="field-<?php echo $selector; ?> " class="form-group uploader"> <div class="fullinput"> <div class="uploader-browse"> <?php echo FileInput::widget(['model' => $model, 'attribute' => $attribute, 'options' => ['id' => $selector, 'onchange' => 'readFile(this, "' . $selector . '", ' . (int) $crop . ', ' . Json::encode($jcropSettings) . ')'], 'pluginOptions' => ['showRemove' => false, 'uploadAsync' => false, 'showUpload' => false, 'showUploadedThumbs' => false, 'showPreview' => false, 'previewFileType' => false]]); ?> </div> </div> <?php if ($crop) { ?> <?php echo Html::hiddenInput($model->formName() . "[{$attribute}-coords][x]", null, ['id' => "{$selector}-coords-x"]); ?> <?php echo Html::hiddenInput($model->formName() . "[{$attribute}-coords][w]", null, ['id' => "{$selector}-coords-w"]); ?> <?php echo Html::hiddenInput($model->formName() . "[{$attribute}-coords][y]", null, ['id' => "{$selector}-coords-y"]); ?> <?php echo Html::hiddenInput($model->formName() . "[{$attribute}-coords][h]", null, ['id' => "{$selector}-coords-h"]); ?> <?php } ?> </div>
/** * Ham lay ra hinh anh trong website theo duong dan * @param string $path duong dan chua anh * @param string $template hinh anh duoc lay ra tu thu muc upload * @return string */ private function getGalleryByPath($path, $template = '') { // Duong dan chua anh $rootPath = Yii::getAlias(Yii::$app->getModule('gallery')->syaDirPath); // Thu muc upload $dirPath = Yii::$app->getModule('gallery')->syaDirUpload; if (!file_exists($path)) { return null; } $entrys = scandir($path); foreach ($entrys as $entry) { if (in_array($entry, ['.', '..', 'cache'])) { continue; } $entryPath = $path . DIRECTORY_SEPARATOR . $entry; if (is_dir($entryPath)) { $template .= self::getGalleryByPath($entryPath, $template); } else { if (in_array(end(explode('.', $entry)), self::$fileType)) { $imgPath = str_replace($rootPath . $dirPath . DIRECTORY_SEPARATOR, '', $entryPath); $template .= Html::beginTag('div', ['class' => 'col-md-3 text-center']); // input chua cac image duoc chon $template .= Html::hiddenInput('let_galleries', '', ['id' => 'let_galleries', 'class' => 'col-md-3 text-center input_image', 'data-type' => 'path']); // View image $template .= Html::beginTag('div', ['class' => 'letImgPreview', 'id' => $imgPath, 'onclick' => 'insertImagePath(this);']); $template .= Html::img('@web/' . $dirPath . DIRECTORY_SEPARATOR . $imgPath, ['style' => 'max-width: 100%; height: 200px;']); $template .= Html::endTag('div'); $template .= Html::endTag('div'); } } } return $template; }
<div id="<?php echo $id; ?> "> <ul class="file-manager-images"> <?php foreach ($images as $image) { ?> <li> <?php echo Html::button('<i class="glyphicon glyphicon-remove-circle"></i>', ['class' => 'btn-remove']); ?> <?php echo Html::img($image->getThumbnail(300, 300)); ?> <?php echo Html::hiddenInput("{$options['name']}[{$image->id}]", $image->url); ?> </li> <?php } ?> </ul> <?php Modal::begin(['header' => Html::tag('h2', Yii::t('app', 'Image manager')), 'toggleButton' => ['label' => $buttonCaption, 'class' => 'btn btn-default'], 'size' => Modal::SIZE_LARGE]); Modal::end(); ?> </div>
/** * @param null $options * @param null $pluginOptions * * @return string * @throws \Exception */ public function getItem($options = null, $pluginOptions = null) { switch ($this->type) { case self::TYPE_TEXT: return Html::input('text', 'Setting[' . $this->code . ']', $this->value, $options != null ? $options : ['placeholder' => $this->getName(), 'class' => 'form-control']); case self::TYPE_EMAIL: return Html::input('email', 'Setting[' . $this->code . ']', $this->value, $options != null ? $options : ['placeholder' => $this->getName(), 'class' => 'form-control']); case self::TYPE_NUMBER: return Html::input('number', 'Setting[' . $this->code . ']', $this->value, $options != null ? $options : ['placeholder' => $this->getName(), 'class' => 'form-control']); case self::TYPE_TEXTAREA: return Html::textarea('Setting[' . $this->code . ']', $this->value, $options != null ? $options : ['placeholder' => $this->getName(), 'class' => 'form-control']); case self::TYPE_COLOR: return ColorInput::widget(['value' => $this->value, 'name' => 'Setting[' . $this->code . ']', 'options' => $options != null ? $options : ['class' => 'form-control']]); case self::TYPE_DATE: return DatePicker::widget(['name' => 'Setting[' . $this->code . ']', 'value' => $this->value, 'options' => $options != null ? $options : ['class' => 'form-control'], 'pluginOptions' => $pluginOptions != null ? $pluginOptions : ['format' => 'yyyy-mm-dd', 'todayHighlight' => true]]); case self::TYPE_TIME: return TimePicker::widget(['name' => 'Setting[' . $this->code . ']', 'value' => $this->value, 'options' => $options != null ? $options : ['class' => 'form-control'], 'pluginOptions' => $pluginOptions != null ? $pluginOptions : ['minuteStep' => 1, 'showSeconds' => true, 'showMeridian' => false]]); case self::TYPE_DATETIME: return DateTimePicker::widget(['name' => 'Setting[' . $this->code . ']', 'value' => $this->value, 'options' => $options != null ? $options : ['class' => 'form-control'], 'pluginOptions' => ['format' => 'yyyy-mm-dd H:i:s', 'todayHighlight' => true]]); case self::TYPE_PASSWORD: return PasswordInput::widget(['name' => 'Setting[' . $this->code . ']', 'value' => $this->value, 'options' => $options != null ? $options : ['class' => 'form-control'], 'pluginOptions' => $pluginOptions != null ? $pluginOptions : ['showMeter' => true, 'toggleMask' => false]]); case self::TYPE_ROXYMCE: return RoxyMceWidget::widget(['id' => 'Setting_' . $this->code, 'name' => 'Setting[' . $this->code . ']', 'value' => $this->value, 'action' => Url::to(['roxymce/default']), 'options' => $options != null ? $options : ['title' => $this->getName()], 'clientOptions' => $pluginOptions != null ? $pluginOptions : []]); case self::TYPE_SELECT: return Select2::widget(['value' => $this->value, 'name' => 'Setting[' . $this->code . ']', 'data' => $this->getStoreRange(), 'options' => $options != null ? $options : ['class' => 'form-control'], 'pluginOptions' => ['allowClear' => true]]); case self::TYPE_MULTI_SELECT: $options['multiple'] = true; if (!isset($options['class'])) { $options['class'] = 'form-control'; } return Select2::widget(['name' => 'Setting[' . $this->code . ']', 'value' => explode(",", $this->value), 'data' => $this->getStoreRange(), 'options' => $options, 'pluginOptions' => ['allowClear' => true]]); case self::TYPE_FILE_PATH: $value = Yii::getAlias($this->store_dir) . DIRECTORY_SEPARATOR . $this->value; return FileInput::widget(['name' => 'Setting[' . $this->code . ']', 'value' => $value, 'options' => $options != null ? $options : ['class' => 'form-control', 'multiple' => false], 'pluginOptions' => $pluginOptions != null ? $pluginOptions : ['previewFileType' => 'any', 'showRemove' => false, 'showUpload' => false, 'initialPreview' => !$this->isNewRecord ? [$this->value] : []]]); case self::TYPE_FILE_URL: $value = $this->store_url . '/' . $this->value; return FileInput::widget(['name' => 'Setting[' . $this->code . ']', 'value' => $value, 'options' => $options != null ? $options : ['class' => 'form-control'], 'pluginOptions' => $pluginOptions != null ? $pluginOptions : ['previewFileType' => 'any', 'showRemove' => false, 'showUpload' => false, 'initialPreviewAsData' => true, 'initialPreviewFileType' => self::fileType(pathinfo($this->value, PATHINFO_EXTENSION)), 'initialPreview' => !$this->isNewRecord ? $value : [], 'initialCaption' => $this->value]]); case self::TYPE_PERCENT: return RangeInput::widget(['name' => 'Setting[' . $this->code . ']', 'value' => $this->value, 'html5Options' => ['min' => 0, 'max' => 100, 'step' => 1], 'options' => $options != null ? $options : ['class' => 'form-control'], 'addon' => ['append' => ['content' => '%']]]); case self::TYPE_SWITCH: $selector = explode(',', $this->store_range); if (count($selector) != 2) { throw new ErrorException(Yii::t('setting', 'Switch Field should have store with 2 value, and negative is first. Example: no,yes'), 500); } return Html::hiddenInput('Setting[' . $this->code . ']', $selector[0]) . SwitchInput::widget(['name' => 'Setting[' . $this->code . ']', 'value' => $selector[1], 'containerOptions' => ['class' => 'nv-switch-container'], 'options' => $options != null ? $options : [], 'pluginOptions' => $pluginOptions != null ? $pluginOptions : ['state' => $this->value == $selector[1], 'size' => 'small', 'offText' => ucfirst($selector[0]), 'onText' => ucfirst($selector[1])]]); case self::TYPE_CHECKBOX: $random = rand(1000, 9999); return Html::checkboxList('Setting[' . $this->code . ']', explode(",", $this->value), $this->getStoreRange(), $options != null ? $options : ['class' => 'nv-checkbox-list checkbox', 'item' => function ($index, $label, $name, $checked, $value) use($random) { $html = Html::beginTag('div'); $html .= Html::checkbox($name, $checked, ['id' => 'Setting_checkbox_' . $label . '_' . $index . '_' . $random, 'value' => $value]); $html .= Html::label($label, 'Setting_checkbox_' . $label . '_' . $index . '_' . $random); $html .= Html::endTag('div'); return $html; }]); case self::TYPE_RADIO: $random = rand(1000, 9999); return Html::radioList('Setting[' . $this->code . ']', $this->value, $this->getStoreRange(), $options != null ? $options : ['class' => 'nv-checkbox-list radio', 'item' => function ($index, $label, $name, $checked, $value) use($random) { $html = Html::beginTag('div'); $html .= Html::radio($name, $checked, ['id' => 'Setting_radio_' . $label . '_' . $index . '_' . $random, 'value' => $value]); $html .= Html::label($label, 'Setting_radio_' . $label . '_' . $index . '_' . $random); $html .= Html::endTag('div'); return $html; }]); case self::TYPE_SEPARATOR: return '<hr>'; default: return Html::input('text', 'Setting[' . $this->code . ']', $this->value, $options != null ? $options : ['placeholder' => $this->getName(), 'class' => 'form-control']); } }
echo Html::hiddenInput('getAll', $widget->getAll); echo Html::hiddenInput('title', $widget->title); echo Html::submitButton($widget->htmlButtonName, ['class' => $widget->buttonClass]); echo Html::endForm(); } ?> </div> <div class="<?php echo $widget->blockClass; ?> " style="<?php echo $widget->blockStyle; ?> "> <?php //if ($widget->html) { if ($widget->pdf) { echo Html::beginForm(['/export/pdf'], 'post'); echo Html::hiddenInput('model', $widget->model); echo Html::hiddenInput('searchAttributes', $widget->searchAttributes); echo Html::hiddenInput('sort', $widget->sort); echo Html::hiddenInput('page', $widget->page); echo Html::hiddenInput('getAll', $widget->getAll); echo Html::hiddenInput('title', $widget->title); echo Html::submitButton($widget->pdfButtonName, ['class' => $widget->buttonClass]); echo Html::endForm(); } ?> </div>
<?php } ?> <div id="sc-destination-new" style="margin-top: 20px;<?php if (is_null($model) && !empty($destinations)) { echo "display:none;"; } ?> "> <?php if (is_null($model)) { $model = new \app\models\UserShippingAddress(); } $form = ActiveForm::begin(['action' => Url::to(['shopcart/destination-save']), 'layout' => 'horizontal']); echo Html::hiddenInput('id', $model->id); ?> <h3>1. <?php echo empty($model->id) ? Yii::t('app', 'Add New Destination') : Yii::t('app', 'Update Destination'); ?> </h3> <?php echo $form->errorSummary([$model]); ?> <div class="row"> <div class="col-sm-4"> <div style="margin-bottom: 4px;"><?php echo Yii::t('app', 'First and Last Name'); ?> </div>
"><?php echo Yii::t('account', 'Action list'); ?> </a></li> </ul> <div class="wrapper wrapper-content animated fadeInRight"> <div class="row"> <div class="col-lg-12"> <div class="ibox "> <div class="ibox-title"> <h5>Nestable custom theme list</h5> </div> <div class="ibox-content"> <?php echo Html::hiddenInput('user_id', Yii::$app->request->get('user_id', '')); ?> <div class="dd" id="nestable2"> <?php echo $treeHtml; ?> </div> </div> </div> </div> </div> </div> </div>
$bgClass = 'bg-danger'; $radioClass = 'radio-danger'; break; } $return = '<div class="radio ' . $radioClass . ' ' . $bgClass . '">'; $return .= '<input id="AdRealEstate-style-' . $value . '" type="radio" name="' . $name . '" value="' . $value . '" style="outline: none;" ' . $checked . '>'; $return .= '<label for="AdRealEstate-style-' . $value . '">' . $label . '</label>'; $return .= '</div>'; return $return; }]); ?> </div> <div class="col-md-12 text-center"> <?php echo Html::hiddenInput('cityString', $modelAdMain->getCity()); ?> <?php if ($modelAdMain->adCategory->adMain->temp == 1) { ?> <?php echo Html::submitButton(Yii::t('app', 'Publish ad'), ['class' => 'btn btn-success']); ?> <?php } else { ?> <?php echo Html::submitButton(Yii::t('app', 'Edit ad'), ['class' => 'btn btn-primary']); ?> <?php }
<?php use yii\bootstrap\Modal; use kartik\grid\GridView; use yii\helpers\ArrayHelper; use yii\bootstrap\Html; // Declare column in product $defaultColumns = [['attribute' => '_id', 'hAlign' => 'center', 'vAlign' => 'middle', 'contentOptions' => ['class' => 'productId']]]; $productColumns = ArrayHelper::merge($defaultColumns, $productColumns); $productColumns[] = ['header' => Yii::t('ecommerce', 'Quantity'), 'hAlign' => 'center', 'vAlign' => 'middle', 'contentOptions' => ['class' => 'productQty'], 'value' => function ($model, $key, $index, $widget) { return Html::textInput('qty', 0, ['class' => 'form-control qty_' . $model->_id, 'onkeyup' => 'return productQtyOrder(this);']); }, 'format' => 'raw']; // Modal product Modal::begin(['id' => 'product_modal', 'size' => 'modal-lg', 'header' => '<h4 class="modal-title" id="myModalLabel">' . Yii::t('ecommerce', 'List Product') . '</h4>', 'toggleButton' => ['label' => '<i class="fa fa-plus"></i> ' . Yii::t('ecommerce', 'Add') . ' ' . Yii::t('ecommerce', 'Product'), 'class' => 'btn btn-xs btn-primary pull-right'], 'footer' => '<button type="button" onclick="addProduct();" class="btn btn-primary">' . Yii::t('ecommerce', 'Add Product') . '</button>']); echo GridView::widget(['panel' => ['heading' => Yii::t('product', 'Product')], 'id' => 'product-grid', 'pjax' => TRUE, 'dataProvider' => $productDataProvider, 'filterModel' => $productSearchModel, 'columns' => $productColumns, 'responsive' => true, 'hover' => true, 'toolbar' => []]); Modal::end(); echo Html::hiddenInput('product_list', \sya\ecommerce\Module::getProductList($model->product), ['id' => 'product_list']); // Register js code $this->registerJs("\r\n // Add or remove product when click product\r\n function productOrder(){\r\n \$('#product-grid-container table tbody tr').click(function(){\r\n // Get id of product and qty\r\n var id = \$(this).find('.productId').text();\r\n var qty = \$(this).find('.productQty input');\r\n \r\n // Get id and qty selected\r\n var product_list = new Array();\r\n if(\$('#product_list').val()){\r\n var productSelected = \$('#product_list').val().split(',');\r\n }else{\r\n var productSelected = null;\r\n }\r\n \r\n if(\$(this).hasClass('selected')){ // remove from hidden field\r\n removeProductId(productSelected, product_list, id, qty, this);\r\n } else { // add too hidden field\r\n addProductId(productSelected, product_list, id, qty, this);\r\n }\r\n });\r\n }\r\n \r\n // Add or remove product when qty = 0\r\n function productQtyOrder(element){\r\n // Get id of product and qty\r\n var id = \$(element).parent().parent().find('.productId').text();\r\n var qty = \$(element);\r\n \r\n // Get id and qty selected\r\n var product_list = new Array();\r\n if(\$('#product_list').val()){\r\n var productSelected = \$('#product_list').val().split(',');\r\n }else{\r\n var productSelected = null;\r\n }\r\n\r\n if(qty.val() == 0){ // remove from hidden field\r\n removeProductId(productSelected, product_list, id, qty, \$(element).parent().parent());\r\n } else { // add too hidden field\r\n addProductId(productSelected, product_list, id, qty, \$(element).parent().parent());\r\n }\r\n }\r\n \r\n // Function remove id product\r\n function removeProductId(productSelected, product_list, id, qty, element){\r\n if(productSelected.length){\r\n j = 0;\r\n for(i =0;i< productSelected.length;i++){\r\n info = productSelected[i].split(':');\r\n if(info[0]!=id){\r\n product_list[j] = info[0]+':'+info[1];\r\n j++;\r\n }\r\n }\r\n }\r\n\r\n \$('#product_list').val(product_list.length?product_list.join():'');\r\n \$(element).removeClass('selected');\r\n qty.val(0);\r\n }\r\n \r\n // Function add id product\r\n function addProductId(productSelected, product_list, id, qty, element){\r\n if (qty.val() == 0) qty.val(1);\r\n \$(element).addClass('selected');\r\n\r\n if(productSelected){\r\n updateValue = false;\r\n for(i =0;i< productSelected.length;i++){\r\n info = productSelected[i].split(':');\r\n if(info[0]==id){\r\n product_list[i] =info[0]+':'+qty.val();\r\n updateValue = true;\r\n }else{\r\n product_list[i]=info[0]+':'+info[1];\r\n }\r\n }\r\n if(!updateValue){\r\n product_list[product_list.length] = id+':'+qty.val();\r\n }\r\n }\r\n \$('#product_list').val(product_list.length?product_list.join():(id+':'+qty.val()));\r\n }\r\n \r\n // Selected product\r\n function setSelect(){\r\n var product_list = \$('#product_list').val();\r\n if(product_list){\r\n var field = product_list.split(',');\r\n var total = field.length;\r\n for(var i=0; i<total; i++){\r\n var product = field[i].split(':');\r\n \$('.qty_'+product[0]).val(product[1]);\r\n \$('.qty_'+product[0]).parent().parent().addClass('selected');\r\n }\t\t\r\n }\r\n }\r\n \r\n // Add product in order\r\n function addProduct(){\r\n var shipping = \$('#syaShipping').val();\r\n \$.ajax({\r\n url: '" . \yii\helpers\Url::to(['/ecommerce/ajax/addproduct']) . "',\r\n type: 'post',\r\n data: {data: \$('#product_list').val(), shipping: shipping},\r\n }).done(function (data) {\r\n \$('#product_info').html(data);\r\n totalProduct();\r\n \$('#product_modal').modal('hide');\r\n });\r\n }\r\n", yii\web\View::POS_END); $this->registerJs("\r\n productOrder();\r\n setSelect();\r\n \$(document).on('pjax:complete', function () {\r\n productOrder();\r\n setSelect();\r\n });\r\n", yii\web\View::POS_READY);
</div> </div> </div> <div class="row"> <div class="col-lg-12"> <div class="ibox float-e-margins"> <div class="ibox-title"> <h5><?php echo Yii::t('common', 'Edit avatar'); ?> </h5> </div> <div class="ibox-content"> <?php $form = ActiveForm::begin(['id' => 'formDefault', 'options' => ['enctype' => 'multipart/form-data']]); echo Html::hiddenInput('submit', 1); ?> <div class="row"> <div class="col-md-6"> <div class="image-crop"> <img src="<?php echo app\helpers\LetHelper::getAvatar(Yii::$app->user->id, LetHelper::URL, true, 48) . '?time=' . time(); ?> "> </div> </div> <div class="col-md-6"> <h4>Preview image</h4> <div class="img-preview img-preview-sm"></div> <h4>Comon method</h4> <p>
private function registerAssets() { GalleryAssets::register($this->getView()); $singleGallery = ['active' => null, 'noactive' => '']; if (!$this->multiple) { $singleGallery = ['active' => '$($(element).parents(".sya_media_library").find(".active")).removeClass("active"); $("#image").val("");', 'noactive' => ' else { removeImageByGallery(element); }']; } $this->getView()->registerJs(' function syaPreviewImage(element){ var listImage = $("#image").val().split(";"), imagesSelected = [], image = $(element).attr("data-info"); $.ajax({ url: "' . Url::to(['/gallery/ajax/getinfoimage']) . '", type: "post", data: {image: image}, }).done(function (data) { $("#sya_gallery_viewpath").html(data); formChangeValue(); }); if (!$(element).parent().hasClass("active")) { ' . ArrayHelper::getValue($singleGallery, "active") . ' // Add image for input if ($("#image").val().length && listImage.length){ var updateImage = false; for(i = 0; i < listImage.length; i++){ if (listImage[i] == image){ updateImage = true; } imagesSelected[i] = listImage[i]; } if (!updateImage){ imagesSelected[imagesSelected.length] = image; } } $("#image").val(imagesSelected.length ? imagesSelected.join(";") : image); $(element).parent().addClass("active"); }' . ArrayHelper::getValue($singleGallery, "noactive") . ' } function formChangeValue(){ $("#sya_gallery_form_preview .form-control").keyup(function(event) { var element = $(this), listImage = $("#image").val().split(";"), url = element.parents("#sya_gallery_form_preview").find("input[name=\'sya_url\']").val(), imageChange = []; for(i = 0; i < listImage.length; i++){ var image = jQuery.parseJSON(listImage[i]); if (image.url == url){ element.each(function(){ image[element.attr("name").replace("sya_", "")] = element.val(); }); $("div[id=\'" + url + "\']").attr("data-info", JSON.stringify(image)); } imageChange[i] = JSON.stringify(image); } $("#image").val(imageChange.length ? imageChange.join(";") : listImage); }); } function removeImageByGallery(element){ var listImage = $("#image").val().split(";"), image = $(element).attr("data-info"); if ($("#image").val().length && listImage.length){ for(i = 0; i < listImage.length; i++){ if (listImage[i] == image){ listImage.splice(i, 1); } } } $("#image").val(listImage.length ? listImage.join(";") : ""); $(element).parent().removeClass("active"); $("#sya_gallery_viewpath").html(""); } function addImageByGallery(type){ var module = "' . $this->moduleName . '", attribute = "' . $this->attribute . '", templateInfomationImage = \'' . str_replace(array("\r\n", "\n", "\r"), '', $this->infomationImage) . '\', templateInfomationImageDetail = \'' . str_replace(array("\r\n", "\n", "\r"), '', $this->infomationImageDetail) . '\', columns = \'' . Json::encode($this->columns) . '\', image = $("#image").val(); if (image.length > 0) { $.ajax({ url: "' . Url::to(['/gallery/ajax/additemimage']) . '", type: "post", data: {type: type, module: module, attribute: attribute, columns: columns, image: image, templateInfomationImage: templateInfomationImage, templateInfomationImageDetail: templateInfomationImageDetail}, }).done(function (data) { if (data.length > 0) { $("' . $this->syaContainer . '").append(data); $("#sya_gallery_modal").modal("hide"); // Reset value $("#sya_gallery_path").find(".active").removeClass("active"); $("#sya_gallery_viewpath").html(""); $(".sya_image_input").val(""); } }); } } // Ham xoa anh function syaremoveImage(element){ var confirmAlert = confirm("' . Yii::t('yii', 'Are you sure you want to delete this item?') . '"); if (confirmAlert == true){ $(element).parents("#imageItem").remove(); // Kiem tra co anh trong gallery hay khong if ($("' . $this->syaContainer . '").children().length == 0) { $("' . $this->syaContainer . '").append(\'' . Html::hiddenInput($this->moduleName . '[' . $this->attribute . ']', '', ['class' => 'form-control']) . '\'); } } } var page = 2; function syaloadMoreImage(){ $.ajax({ url: "' . Url::to(['/gallery/ajax/getgallerypath']) . '", type: "post", data: {type: $("#insert_image").attr("data-type"), page: page}, }).done(function (data) { if (data != "") { $(".sya_media_library").append(data); page += 1; } }); } function syaGetGalleryByPath(){ $.ajax({ url: "' . Url::to(['/gallery/ajax/getgallerypath']) . '", type: "post", data: {type: "' . self::TYPE_PATH . '"}, }).done(function (data) { $(".sya_media_library").html(data); $(".sya_remove_img").hover(function(){ $(this).removeClass("glyphicon-ok"); $(this).addClass("glyphicon-remove"); }, function(){ $(this).addClass("glyphicon-ok"); $(this).removeClass("glyphicon-remove"); }); }); } ', View::POS_END); $this->getView()->registerJs(' // Sap xep anh $("' . $this->syaContainer . '").sortable({}); // Dropzone drop and drag file Dropzone.options.myAwesomeDropzone = { uploadMultiple: true, parallelUploads: 100, maxFiles: 100, paramName: "image", params: { type: "' . self::TYPE_UPLOAD . '", module: "' . $this->moduleName . '", columns: \'' . Json::encode($this->columns) . '\' }, autoDiscover: false, url: "' . Url::to(['/gallery/ajax/additemimage']) . '", headers: { "Accept": "*/*", "' . \yii\web\Request::CSRF_HEADER . '": "' . Yii::$app->getRequest()->csrfToken . '", "Access-Control-Allow-Origin": "*" }, // Dropzone settings init: function() { this.on("sendingmultiple", function(image, xhr, formData) { formData.processData = false; formData.contentType = false; formData.enctype = "multipart/form-data"; }); this.on("complete", function(files, responseText, e) { syaGetGalleryByPath(); $(".custom_modal_gallery a[data-type=\'' . self::TYPE_PATH . '\']").tab("show"); $(".sya_media_library").prepend(responseText); }); } } $(".custom_modal_gallery a[data-toggle=\'tab\']").on("shown.bs.tab", function (e) { var tabs = $(e.target).parents(".tabs-left"), image = tabs.find(".active").find(".sya_image_input"); if ($(".sya_media_library").children().length <= 0 && $(e.target).attr("data-type") == "' . self::TYPE_PATH . '"){ syaGetGalleryByPath(); } // Forcus input image.focus(); tabs.find(".sya_image_input").removeAttr("id"); image.attr("id", "image"); $("#insert_image").attr("data-type", $(e.target).attr("data-type")); }) $(".sya_input_info_image").on("input",function(e){ var image = $(this).val(); $.ajax({ url: "' . Url::to(['/gallery/ajax/getimagepreview']) . '", type: "post", data: {image: image}, }).done(function (data) { $("#embed_url_settings").html(data); $("#image").val("{\\"url\\": \\"" + image + "\\", \\"title\\":\\"\\", \\"caption\\":\\"\\", \\"alt_text\\":\\"\\"}"); formChangeValue(); }); }); $("#insert_image").click(function() { addImageByGallery($(this).attr("data-type")); }); $( ".sya_media_library" ).scroll(function() { var scrollPosition = $(this).scrollTop() + $(this).outerHeight(), divTotalHeight = $(this)[0].scrollHeight + parseInt($(this).css("padding-top"), 10) + parseInt($(this).css("padding-bottom"), 10) + parseInt($(this).css("border-top-width"), 10) + parseInt($(this).css("border-bottom-width"), 10); if(scrollPosition + 20 == divTotalHeight) { syaloadMoreImage(); } }); ', View::POS_READY); }
/** * Function generate list product order * @param array $products list product [ * 1 => [ * 'id' => 1, * 'sku' => '123', * 'title' => 'sdsd', * 'price' => 50000, * 'quantity' => 1, * 'is_marketing' => '1', * ] * ] * @return string */ public function generateProductOrder($products = [], $shipping = 0) { if (!empty($products)) { // IF shipping is not number then assign value shipping = 0 if (!is_integer(intval($shipping))) { $shipping = 0; } // Get model name of product $ecommerce = Ecommerce::module(); $modelName = end(explode('\\', $ecommerce->itemModule)); // Begin list product order $template = Html::beginTag('div', ['class' => 'table-responsive']); $template .= Html::beginTag('table', ['class' => 'table table-striped']); // Begin header table $template .= Html::beginTag('thead'); $template .= Html::beginTag('tr'); $template .= Html::beginTag('th'); $template .= Yii::t('ecommerce', 'ID'); $template .= Html::endTag('th'); $template .= Html::beginTag('th'); $template .= Yii::t('ecommerce', 'Sku'); $template .= Html::endTag('th'); $template .= Html::beginTag('th'); $template .= Yii::t('ecommerce', 'Title'); $template .= Html::endTag('th'); $template .= Html::beginTag('th'); $template .= Yii::t('ecommerce', 'Price'); $template .= Html::endTag('th'); $template .= Html::beginTag('th'); $template .= Yii::t('ecommerce', 'Quantity'); $template .= Html::endTag('th'); $template .= Html::beginTag('th'); $template .= Yii::t('ecommerce', 'Total Price'); $template .= Html::endTag('th'); $template .= Html::endTag('tr'); $template .= Html::endTag('thead'); // End header table // Begin list product $template .= Html::beginTag('tbody'); $sumTotal = 0; foreach ($products as $product) { // Get value in product $id = ArrayHelper::getValue($product, 'id', ''); $sku = ArrayHelper::getValue($product, 'sku', ''); $title = ArrayHelper::getValue($product, 'title', ''); $price = ArrayHelper::getValue($product, 'price', 0); $quantity = ArrayHelper::getValue($product, 'quantity', 0); $is_marketing = ArrayHelper::getValue($product, 'is_marketing', '1'); $total = $price * $quantity; $sumTotal += $total; $template .= Html::beginTag('tr'); $template .= Html::beginTag('td', ['class' => 'text-vertical']); $template .= Html::tag('span', $id, ['class' => 'product_id']); $template .= Html::hiddenInput($modelName . '[product][' . $id . '][id]', $id, ['class' => 'form-control', 'readonly' => true]); $template .= Html::endTag('td'); $template .= Html::beginTag('td', ['class' => 'text-vertical']); $template .= $sku; $template .= Html::hiddenInput($modelName . '[product][' . $id . '][sku]', $sku, ['class' => 'form-control', 'readonly' => true]); $template .= Html::endTag('td'); $template .= Html::beginTag('td', ['class' => 'text-vertical']); $template .= $title; $template .= Html::hiddenInput($modelName . '[product][' . $id . '][title]', $title, ['class' => 'form-control', 'readonly' => true]); $template .= Html::endTag('td'); $template .= Html::beginTag('td', ['class' => 'text-vertical']); $template .= Yii::$app->formatter->asDecimal($price, 0) . ' VNĐ'; $template .= Html::hiddenInput($modelName . '[product][' . $id . '][price]', $price, ['class' => 'form-control product_price', 'readonly' => true]); $template .= Html::endTag('td'); $template .= Html::beginTag('td', ['style' => 'width: 5%;']); $template .= Html::textInput($modelName . '[product][' . $id . '][quantity]', $quantity, ['class' => 'form-control product_qty text-center', 'onkeyup' => 'return totalPriceProduct(this);']); $template .= Html::endTag('td'); $template .= Html::beginTag('td', ['class' => 'text-vertical', 'colspan' => 2]); $template .= Html::tag('span', Yii::$app->formatter->asDecimal($total, 0) . ' VNĐ', ['class' => 'product_total', 'data-total' => $total]); $template .= Html::endTag('td'); $template .= Html::endTag('tr'); } // Begin shipping $template .= Html::beginTag('tr'); $template .= Html::beginTag('td', ['colspan' => '5', 'class' => 'text-right', 'style' => 'vertical-align: middle;']); $template .= Yii::t('ecommerce', 'Shipping') . ': '; $template .= Html::endTag('td'); $template .= Html::beginTag('td', ['width' => '100px']); $template .= Html::textInput('shipping', Yii::$app->formatter->asDecimal($shipping, 0), ['class' => 'form-control pull-left', 'onkeyup' => 'return addShipping(this);']); $template .= Html::hiddenInput($modelName . '[shipping]', $shipping, ['id' => 'syaShipping', 'class' => 'form-control product_total', 'readonly' => true, 'data-total' => $shipping]); $template .= Html::endTag('td'); $template .= Html::beginTag('td', ['style' => 'vertical-align: middle;']); $template .= ' VNĐ'; $template .= Html::endTag('td'); $template .= Html::endTag('tr'); // End shipping // Begin total product $template .= Html::beginTag('tr'); $template .= Html::beginTag('td', ['colspan' => '5', 'class' => 'text-right']); $template .= Yii::t('ecommerce', 'Total') . ': '; $template .= Html::endTag('td'); $template .= Html::beginTag('td', ['colspan' => '2']); $template .= Html::tag('span', Yii::$app->formatter->asDecimal($sumTotal + $shipping, 0), ['id' => 'product_total']) . ' VNĐ'; $template .= Html::endTag('td'); $template .= Html::endTag('tr'); // End total product $template .= Html::endTag('tbody'); // End list product $template .= Html::endTag('table'); // End list product order $template .= Html::endTag('div'); // End table-responsive return $template; } return null; }
echo Html::endTag('div'); ?> </div> <?php ActiveForm::end(); ?> </div> <?php } Pjax::end(); ?> <?php if (count($basket)) { ?> <?php echo Html::beginForm(['site/buy'], 'post', ['enctype' => 'multipart/form-data']); ?> <?php echo Html::hiddenInput('user_id', Yii::$app->user->identity->id); ?> <?php echo Html::submitButton('Оформить заказ (здесь - уже приобрести)', ['class' => 'btn btn-success', 'name' => 'buy']); ?> <?php echo Html::endForm(); } else { ?> <p>Корзина пуста.</p> <?php }
<?php use yii\bootstrap\Modal; use kartik\grid\GridView; use yii\helpers\ArrayHelper; use yii\bootstrap\Html; use sya\ecommerce\Ecommerce; $ecommerce = Ecommerce::module(); // Declare column in product $defaultColumns = [['attribute' => '_id', 'hAlign' => 'center', 'vAlign' => 'middle', 'contentOptions' => ['class' => 'productId']]]; $productColumns = ArrayHelper::merge($defaultColumns, $productColumns); $productColumns[] = ['header' => Yii::t('ecommerce', 'Quantity'), 'hAlign' => 'center', 'vAlign' => 'middle', 'contentOptions' => ['class' => 'productQty'], 'value' => function ($model, $key, $index, $widget) use($ecommerce) { $options = ['class' => 'form-control qty_' . $model->_id]; if ($ecommerce->multiple) { $options['onkeyup'] = 'return productQtyOrder(this);'; } else { $options['readonly'] = ''; } return Html::textInput('qty', 1, $options); }, 'format' => 'raw']; // Modal product Modal::begin(['id' => 'product_modal', 'size' => 'modal-lg', 'header' => '<h4 class="modal-title" id="myModalLabel">' . Yii::t('ecommerce', 'List Product') . '</h4>', 'toggleButton' => ['label' => '<i class="fa fa-plus"></i> ' . Yii::t('ecommerce', 'Create') . ' ' . Yii::t('ecommerce', 'Product'), 'class' => 'btn btn-xs btn-primary pull-right'], 'footer' => '<button type="button" onclick="addProduct();" class="btn btn-primary">' . Yii::t('ecommerce', 'Create') . ' ' . Yii::t('ecommerce', 'Product') . '</button>']); echo GridView::widget(['panel' => ['heading' => Yii::t('ecommerce', 'Product')], 'id' => 'product-grid', 'pjax' => TRUE, 'dataProvider' => $productDataProvider, 'filterModel' => $productSearchModel, 'columns' => $productColumns, 'responsive' => true, 'hover' => true, 'toolbar' => []]); Modal::end(); echo Html::hiddenInput('product_list', \sya\ecommerce\Module::getProductList($model->product), ['id' => 'product_list']); echo Html::hiddenInput(\yii\helpers\StringHelper::basename(get_class($model)) . '[product_text]', $model->product_text, ['id' => 'product_text']); // Register js code $this->registerJs("\r\n // Add or remove product when click product\r\n function productOrder(){\r\n \$('#product-grid-container table tbody tr').click(function(){\r\n // Get id of product and qty\r\n var id = \$(this).find('.productId').text();\r\n var qty = \$(this).find('.productQty input');\r\n \r\n // Get id and qty selected\r\n var product_list = new Array();\r\n if(\$('#product_list').val()){\r\n var productSelected = \$('#product_list').val().split(',');\r\n }else{\r\n var productSelected = null;\r\n }\r\n \r\n if(\$(this).hasClass('selected')){ // remove from hidden field\r\n removeProductId(productSelected, product_list, id, qty, this);\r\n } else { // add too hidden field\r\n addProductId(productSelected, product_list, id, qty, this);\r\n }\r\n });\r\n }\r\n \r\n // Add or remove product when qty = 0\r\n function productQtyOrder(element){\r\n // Get id of product and qty\r\n var id = \$(element).parent().parent().find('.productId').text();\r\n var qty = \$(element);\r\n \r\n // Get id and qty selected\r\n var product_list = new Array();\r\n if(\$('#product_list').val()){\r\n var productSelected = \$('#product_list').val().split(',');\r\n }else{\r\n var productSelected = null;\r\n }\r\n\r\n if(qty.val() == 0){ // remove from hidden field\r\n removeProductId(productSelected, product_list, id, qty, \$(element).parent().parent());\r\n } else { // add too hidden field\r\n addProductId(productSelected, product_list, id, qty, \$(element).parent().parent());\r\n }\r\n }\r\n \r\n // Function remove id product\r\n function removeProductId(productSelected, product_list, id, qty, element){\r\n if(productSelected.length){\r\n j = 0;\r\n for(i =0;i< productSelected.length;i++){\r\n info = productSelected[i].split(':');\r\n if(info[0]!=id){\r\n product_list[j] = info[0]+':'+info[1];\r\n j++;\r\n }\r\n }\r\n }\r\n\r\n \$('#product_list').val(product_list.length?product_list.join():'');\r\n \$(element).removeClass('selected');\r\n qty.val(0);\r\n }\r\n \r\n // Function add id product\r\n function addProductId(productSelected, product_list, id, qty, element){\r\n if (qty.val() == 0) qty.val(1);\r\n \$(element).addClass('selected');\r\n\r\n if(productSelected){\r\n updateValue = false;\r\n for(i =0;i< productSelected.length;i++){\r\n info = productSelected[i].split(':');\r\n if(info[0]==id){\r\n product_list[i] =info[0]+':'+qty.val();\r\n updateValue = true;\r\n }else{\r\n product_list[i]=info[0]+':'+info[1];\r\n }\r\n }\r\n if(!updateValue){\r\n product_list[product_list.length] = id+':'+qty.val();\r\n }\r\n }\r\n \$('#product_list').val(product_list.length?product_list.join():(id+':'+qty.val()));\r\n }\r\n \r\n // Selected product\r\n function setSelect(){\r\n var product_list = \$('#product_list').val();\r\n if(product_list){\r\n var field = product_list.split(',');\r\n var total = field.length;\r\n for(var i=0; i<total; i++){\r\n var product = field[i].split(':');\r\n \$('.qty_'+product[0]).val(product[1]);\r\n \$('.qty_'+product[0]).parent().parent().addClass('selected');\r\n }\t\t\r\n }\r\n }\r\n \r\n // Add product in order\r\n function addProduct(){\r\n var shipping = \$('#syaShipping').val();\r\n \$.ajax({\r\n url: '" . \yii\helpers\Url::to(['/ecommerce/ajax/addproduct']) . "',\r\n type: 'post',\r\n dataType: 'json',\r\n data: {data: \$('#product_list').val(), shipping: shipping},\r\n }).done(function (data) {\r\n \$('#product_info').html(data.template);\r\n \$('#product_text').val(data.titles);\r\n totalProduct();\r\n \$('#product_modal').modal('hide');\r\n });\r\n }\r\n", yii\web\View::POS_END); $this->registerJs("\r\n productOrder();\r\n setSelect();\r\n \$(document).on('pjax:complete', function () {\r\n productOrder();\r\n setSelect();\r\n });\r\n", yii\web\View::POS_READY);
/** * @return string */ public function renderField() { switch ($this->type) { case 'textInput': return Html::textInput($this->param_name, $this->param_value, ['class' => 'form-control']); break; case 'textarea': return Html::textarea($this->param_name, $this->param_value, ['class' => 'form-control']); break; case 'checkbox': return Html::hiddenInput($this->param_name, 0) . \oakcms\bootstrapswitch\Switcher::widget(['name' => $this->param_name, 'checked' => $this->param_value]); break; case 'language': return Html::dropDownList($this->param_name, $this->param_value, ArrayHelper::map(Language::getLanguages(), 'language_id', 'name'), ['class' => 'form-control']); break; case 'getTheme': $files = scandir(Yii::getAlias('@app') . '/templates/frontend'); $items = []; foreach ($files as $file) { //if(!is_file($file) AND $file != '.' AND $file != '..') { if ($file != '.' and $file != '..') { $items[$file] = $file; } } return Html::dropDownList($this->param_name, $this->param_value, $items, ['class' => 'form-control']); break; } }