Fine uploader message error - yii

I am using yii framework with fine uploader. When i moved my project on a new server I suddenly got this message error in console:
Error: element not found file
throw new Error('element not found ' + type);
This is the code why I'm getting the error. But I don't understant what this do(this is from the library fine uploader)
_find: function(parent, type){
var element = qq(parent).getByClass(this._options.classes[type])[0];
if (!element){
throw new Error('element not found ' + type);
}
return element;
},
this is the php code:
<?php
$this->widget('ext.fineuploader.EFineUploader', array(
'id' => 'FineUploader',
'config' => array(
'autoUpload' => true,
'text' => array(
'uploadButton' => 'Adaugă CV'
),
'request' => array(
'endpoint' => $this->createUrl("/cariera/uploadTmpFile"),
'params' => array('YII_CSRF_TOKEN' => Yii::app()->request->csrfToken),
),
'retry' => array('enableAuto' => false, 'preventRetryResponseProperty' => true),
'chunking' => array('enable' => true, 'partSize' => 100), //bytes
'callbacks' => array(
'onComplete' => "js:function(id, name, response){ "
. " if(response.success){"
. " $('#Candidate_cv_path_em_').hide();"
. " $('#Candidate_cv_path').val(response.folder+'/'+name);"
. " var width = $('.qq-upload-button > div').width();"
. " if($('.qq-upload-button > div.progressBar')){"
. " $('.qq-upload-button > div.progressBar').remove();"
. " }"
. " $('.qq-upload-button').prepend('<div class=\"progressBar\"></div>');"
. " $('.qq-upload-button > div.progressBar').animate({width: '150px'}, 1000, function(){ $('.qq-upload-button > div').html('CV atașat'); });"
. " }"
. "}",
'onError' => "js:function(id, name, errorReason){ $('#Candidate_cv_path_em_').html(errorReason).show();}",
),
'validation' => array(
'allowedExtensions' => array(),
'sizeLimit' => 2 * 1024 * 1024, //maximum file size in bytes
'minSizeLimit' => 1, // minimum file size in bytes
'acceptFiles' => 'application/pdf, application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/msword'
),
)
));
echo "<span class='info_upload'>(.pdf, .doc, .docx)</span>";
// echo $form->error($applicant, 'cv', array('class' => "errorMessage errorCv"));
// echo $form->labelEx($applicant, 'cv', array('label' => '<span class="progressBar"></span>Upload CV', 'class' => 'uploadcv'));
// echo $form->fileField($applicant, 'cv', array('size' => '1', 'class' => 'hiddenInputFile'));
?>
Can someone help me with this ?
Update:
I noticed that it is not generated this html part on the new server:
<ul class="qq-upload-list">
<li class=" qq-upload-success">
<div style="display: none; width: 100%;" class="qq-progress-bar">
</div>
<span style="display: none;" class="qq-upload-spinner"></span>
<span class="qq-upload-finished"></span>
<span class="qq-upload-file">free_cv_sample_template.pdf</span>
<span style="display: inline;" class="qq-upload-size">0.1MB</span>
<a style="display: none;" class="qq-upload-cancel" href="#">Cancel</a>
<a class="qq-upload-retry" href="#">Retry</a>
<a class="qq-upload-delete" href="#">Delete</a>
<span class="qq-upload-status-text"></span>
</li>
</ul>
Why ?

Related

Custom wordpress taxonomy with v2 api and vue

I'm using the wordpress v2 api to display custom posttypes. Everything works as expected, only the custom taxonomy returns their ID instead of the name.
I've read that adding ?embed to the endpoint and show_in_rest adds posttypes and taxonomies to the api result and this sort of looks to be the case. But the taxonomy name isn't found in the result.
Am I missing something?
Here are some snippets of my code...
// taxonomy snippet
register_taxonomy('types',array('work'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'type' ),
'show_in_rest' => true,
'rest_base' => 'work-api',
'rest_controller_class' => 'WP_REST_Terms_Controller'
// custom posttype snippet
$args = array(
'labels' => $labels,
'description' => 'All projects',
'public' => true,
'menu_icon' => 'dashicons-layout',
'supports' => array('title', 'editor', 'thumbnail'),
'has_archive' => true,
'show_in_rest' => true,
'rest_base' => 'work-api',
'rest_controller_class' => 'WP_REST_Posts_Controller'
);
// DOM snippet
<div id="workfeed" class="work" style="margin-top: 100px;">
<div v-for="(item,index) in work" class="row" :data-index="index">
<div class="col">
<img :src="item._embedded['wp:featuredmedia'][0].source_url" />
</div>
<div class="col">
<h3>{{ item.title.rendered }}</h3>
{{ item.content.rendered }}
{{ item._embedded['wp:term'][0].taxonomy }}
</div>
</div>
</div>

Add field in product Prestashop 1.7

Why is prestashop don't save my modification into database?
Using prestashop 1.7
/override/classes/Product.php
class Product extends ProductCore {
public $por_gan; public function __construct ($idProduct = null, $idLang = null, $idShop = null) {
$definition = self::$definition;
$definition['fields']['por_gan'] = array('type' => self::TYPE_INT, 'required' => false);
parent::__construct($idProduct, $idLang, $idShop); } }
In ProductInformation.php
->add('por_gan', 'Symfony\Component\Form\Extension\Core\Type\NumberType', array(
'required' => false,
'label' => $this->translator->trans('Beneficio', [], 'Admin.Catalog.Feature'),
'constraints' => array(
new Assert\NotBlank(),
new Assert\Type(array('type' => 'numeric'))
),
))
In form.html.twing
<div class="col-md-6">
<label class="form-control-label">% de beneficio</label
{{ form_widget(form.step1.por_gan) }}
</div>
Thanks
I’ve successfully added an extra tab in admin product page.
It's working fine. I think a better approach would be to create a module in order to make that modification easier to maintain.
Or you can use displayAdminProductsExtra hook, actionProductUpdate hook and actionProductAdd
The extra field is : frais_a_prevoir
I show all the files to modify but you have to check where the modification should be done inside the file (make a search and you will find)
Override /classes/Product.php
In class /classes/Product.php, there are 3 modifications to do :
1)
/** #var string Frais à prévoir */
public $frais_a_prevoir;
2)
'frais_a_prevoir' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
3)
$sql->select(
'p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, pl.`frais_a_prevoir`, pl.`link_rewrite`, pl.`meta_description`,
pl.`meta_keywords`, pl.`meta_title`, pl.`name`, pl.`available_now`, pl.`available_later`, image_shop.`id_image` id_image, il.`legend`, m.`name` AS manufacturer_name,
(DATEDIFF(product_shop.`date_add`,
DATE_SUB(
"'.$now.'",
INTERVAL '.$nb_days_new_product.' DAY
)
) > 0) as new'
);
In /src/PrestaShopBundle/Resources/views/Admin/Product/form.html.twig
<ul class="nav nav-tabs bordered">
<li id="tab_description_short" class="nav-item">{{ 'Summary'|trans({}, 'Admin.Catalog.Feature') }}</li>
<li id="tab_description" class="nav-item">{{ 'Description'|trans({}, 'Admin.Global') }}</li>
<li id="tab_frais_a_prevoir" class="nav-item">{{ 'frais_a_prevoir'|trans({}, 'Admin.Global') }}</li>
</ul>
<div class="tab-content bordered">
<div class="tab-pane panel panel-default active" id="description_short">
{{ form_widget(form.step1.description_short) }}
</div>
<div class="tab-pane panel panel-default " id="description">
{{ form_widget(form.step1.description) }}
</div>
<div class="tab-pane panel panel-default " id="frais_a_prevoir">
{{ form_widget(form.step1.frais_a_prevoir) }}
</div>
</div>
In /src/PrestaShopBundle/Form/Admin/Product/productInformation.php
->add('frais_a_prevoir', 'PrestaShopBundle\Form\Admin\Type\TranslateType', array(
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextareaType',
'options' => [
'attr' => array('class' => 'autoload_rte'),
'required' => false
],
'locales' => $this->locales,
'hideTabs' => true,
'label' => $this->translator->trans('frais_a_prevoir', [], 'Admin.Global'),
'required' => false
))
in src/PrestaShopBundle/Model/Product/AdminModelAdapter.php:
$this->translatableKeys = array(
'name',
'description',
'description_short',
'frais_a_prevoir',
'link_rewrite',
'meta_title',
'meta_description',
'available_now',
'available_later',
'tags',
);
//define unused key for manual binding
$this->unmapKeys = array('name',
'description',
'description_short',
'frais_a_prevoir',
'images',
'related_products',
'categories',
'suppliers',
'display_options',
'features',
'specific_price',
'virtual_product',
'attachment_product',
);
2)
'frais_a_prevoir' => $this->product->frais_a_prevoir,
In database, add a column frais_a_prevoir in table product_lang
Here is an option to do this using module and does not change core files
in your MyModule.php
use PrestaShopBundle\Form\Admin\Type\TranslateType;
use PrestaShopBundle\Form\Admin\Type\FormattedTextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
public function hookDisplayAdminProductsExtra($params)
{
$productAdapter = $this->get('prestashop.adapter.data_provider.product');
$product = $productAdapter->getProduct($params['id_product']);
$formData = [
'ebay_reference' => $product->ebay_reference,
];
$formFactory = $this->get('form.factory');
$form = $formFactory->createBuilder(FormType::class, $formData)
->add('ebay_reference', TranslateType::class, array(
'required' => false,
'label' => 'Ebay reference',
'locales' => Language::getLanguages(),
'hideTabs' => true,
'required' => false
))
->getForm()
;
return $this->get('twig')->render(_PS_MODULE_DIR_.'MyModule/views/display-admin-products-extra.html.twig', [
'form' => $form->createView()
]) ;
}
public function hookActionAdminProductsControllerSaveBefore($params)
{
$productAdapter = $this->get('prestashop.adapter.data_provider.product');
$product = $productAdapter->getProduct($_REQUEST['form']['id_product']);
foreach(Language::getLanguages() as $language){
$product->ebay_reference[ $language['id_lang'] ] =
$_REQUEST['form']['ebay_reference'][$language['id_lang']];
}
$product->save();
}
in your display-admin-products-extra.html.twig
<div class="row" >
<div class="col-md-12">
<div class="form-group">
<h3>Ebay reference</h3>
{{ form_errors(form.ebay_reference) }}
{{ form_widget(form.ebay_reference) }}
</div>
</div>
</div>

Bootstrap3 Modal not working with GridView's pjax

I have a following GridView, but unfortunately Bootstrap modal isn't working properly if I have used Pjax pagination or search. Well, the modal does show up, but it won't submit the form. And when I leave the modal out of Pjax(), then it isn't loaded at all.
Pjax::begin(['id' => 'pjax_id', 'timeout' => false, 'enablePushState' => false]);
echo GridView::widget([
'dataProvider' => $details,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
['format' => 'raw',
'label' => 'Category',
'value' => function ($data) {
$string = '';
foreach ($data['Category'] as $category) {
$string .= $category->category_name . '<br/>';
}
return $string;
}],
'book_name',
['format' => 'raw',
'contentOptions' => ['class' => 'form-cell'],
'label' => '',
'value' => function ($data) {
$buttons = Html::button('Edit', ['class' => 'btn btn-default mleft modallink', 'data-toggle' => 'modal', 'data-target' => '#'.$data->cat_id]);
return $buttons;
}
],
[
'format' => 'raw',
'label' => '',
'value' => function ($data) {
if (Yii::$app->user->identity->user_type == 'admin') {
$string = '</span>';
$string .= '<a class=\'mleft\' href=\''.Url::to(['category/update', 'id' => $data->cat_id]).'\'><span class="glyphicon glyphicon-pencil"></span></a>';
return $string;
}
}
],
],
]);
$details = $details->getModels();
foreach ($details as $detail) {
?>
<div class="modal fade" id="<?= $detail->cat_id ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel"><?= $detail->category_name ?></h4>
</div>
<div class="modal-body">
<?php
echo Html::beginForm(Url::to(['category/details', 'id' => $detail->cat_id]), 'post', ['id' => 'popup']);
echo Html::beginTag('div', ['class' => 'form-group']);
echo Html::activeLabel($detail, 'cat_description');
echo Html::activeTextarea($detail, 'cat_description', ['class' => 'form-control']);
echo Html::endTag('div');
echo Html::beginTag('div', ['class' => 'form-group']);
echo Html::activeLabel($detail, 'link');
echo Html::activeInput('text', $detail, 'link', ['class' => 'form-control']);
echo Html::endTag('div');
echo Html::beginTag('div', ['class' => 'form-group']);
echo Html::activeLabel($detail, 'resource');
echo Html::activeInput('text', $detail, 'resource', ['class' => 'form-control']);
echo Html::endTag('div');
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<?= Html::submitButton('Submit', ['class' => 'btn btn-success']) ?>
<?= Html::endForm(); ?>
</div>
</div>
</div>
</div>
<?php
}
Pjax::end();
So how do I keep GridView's Pjax functionality so that the modal still works?
Pjax widget has a formSelector attribute that, by default, will find all forms with data-pjax attribute set to something not falsy.
The easiest way to fix your form is to add that attribute to your form definition:
echo Html::beginForm(
Url::to(['category/details', 'id' => $detail->cat_id]),
'post',
[
'id' => 'popup',
'data-pjax' => 1,
]
);

How to show timepicker based jqrelcopy yii?

How to show timepicker based yiibooster, with Jqrelcopy.
I've code like this :
<div class="control-group "><label class="control-label required">Jam Kerja</label>
<div class="controls">
<a id="copylink" href="#" rel=".copy">Tambah Jam Kerja / Shift</a>
<div class="row copy">
<?php echo CHtml::label('',''); ?>
<?php $this->widget('bootstrap.widgets.TbTimePicker',
array(
'name' => 'some_time',
'value' => '00:00',
'htmlOptions'=>array('width'=>'50px'),
'noAppend' => true, // mandatory
'options' => array(
'disableFocus' => true, // mandatory
'showMeridian' => false // irrelevant
),
)
);
?>
<?php
$this->widget('bootstrap.widgets.TbTimePicker',
array(
'name' => 'some_time',
'value' => '00:00',
'noAppend' => true, // mandatory
'options' => array(
'disableFocus' => true, // mandatory
'showMeridian' => false // irrelevant
)
)
);
?>
</div>
</div>
</div>
When I add new, Timepicker always on field 1. Can't on field changed.

Validation fails on dropdown list input item

Friends,
I have a registration form with several items and the drop down list on these items seems like its not being picked up by the form submission.
The View:
</div>
<div class="row">
<?php echo CHtml::activeLabel($model, 'Gjinia'); ?>
<?php echo CHtml::dropDownList('sex', 0, $data = array(0 => 'Mashkull', 1 => 'Femer'))
?>
</div>
<div class="row">
<?php echo CHtml::activeLabel($model, 'Arsimimi'); ?>
<?php echo CHtml::dropDownList('education', 0, $data = array(0 => 'Ulet', 1 => 'Mesem', 2 => 'Larte')) ?>
</div>
<div class="row">
<?php echo CHtml::activeLabel($model, 'Statusi Martesor'); ?>
<?php echo CHtml::dropDownList('marital_status', 0, $data = array(0 => 'Beqar/e', 1 => 'I/E divorcuar', 2 => 'I/E martuar', 3 => 'I/E veje')) ?>
</div>
Validation rules:
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('name, lastname, sex, education,
marital_status, employment,
dob, municipality, address,
cell_no, email, initialPassword,
repeatPassword', 'required'),
array('sex, employment, municipality,', 'numerical', 'integerOnly' => true),
array('email, initialPassword, repeatPassword, name, lastname', 'length', 'max' => 100),
array('initialPassword, repeatPassword', 'required', 'on' => 'insert'),
array('initialPassword, repeatPassword', 'length', 'min' => 6, 'max' => 40),
array('initialPassword', 'compare', 'compareAttribute' => 'repeatPassword'),
);
}
After submitting my form I am getting the following when I do a print_r on $_POST['Auser']:
Array ( [name] => Name [lastname] => Lname [address] => B ellit
[cell_no] => 044 568 178 [email] => gzzi#gmail.com [id] => [sex] =>
[education] => [marital_status] => [employment] => [industry] => [dob] =>
[municipality] => [password] => )
and the error message:
Sex cannot be blank.
Education cannot be blank.
Marital Status cannot be blank.
Employment cannot be blank.
Dob cannot be blank.
Municipality cannot be blank.
Your dropdownlist should be defined like this:
<div class="row">
<?php echo CHtml::activeLabel($model, 'Statusi Martesor'); ?>
<?php echo CHtml::activeDropDownList($model, 'marital_status', array(0 => 'Beqar/e', 1 => 'I/E divorcuar', 2 => 'I/E martuar', 3 => 'I/E veje')) ?>
</div>
Instead of:
<div class="row">
<?php echo CHtml::activeLabel($model, 'Statusi Martesor'); ?>
<?php echo CHtml::dropDownList('marital_status', 0, $data = array(0 => 'Beqar/e', 1 => 'I/E divorcuar', 2 => 'I/E martuar', 3 => 'I/E veje')) ?>
</div>
In the first instance (where I used CHtml::activeDropDownList($model, 'attribute_name')), you can access your dropdown attributes after doing $model->attributes = $_POST['ModelName']; like this $model->sex, $model->marital_status because the POST array is ging to be like: $_POST['ModelName']['sex'], $_POST['ModelName']['marital_status']
When you use CHtml::dropDownList('field_name', 'selected_value', array('option1', 'option2')), the POST array is of the form $_POST['field_name'] and for ActiveRecord, what you want is $_POST['ModelName']['field_name']
I hope that solves your question.