images processing when editing post and adding post
This commit is contained in:
parent
f63f3bd709
commit
b34df98d31
|
|
@ -136,16 +136,20 @@ class OfferForm extends ComponentBase
|
|||
'description_tm' => 'required',
|
||||
'description_en' => 'required',
|
||||
'description_ru' => 'required',
|
||||
// 'ends_at' => 'required|date',
|
||||
'payment_term_id' => 'required',
|
||||
'packaging' => 'required',
|
||||
'delivery_term_id' => 'required',
|
||||
'currency_id' => 'required',
|
||||
'measure_id' => 'required',
|
||||
'new_img' => 'required'
|
||||
// 'new_img' => 'required'
|
||||
];
|
||||
$this->validateForm($data, $rules);
|
||||
|
||||
// validate if no old images and new images
|
||||
if(!isset($data['new_img']) && !isset($data['old_img'])) {
|
||||
throw new ValidationException(['no_images' => 'Хотя бы 1 фото должно быть']);
|
||||
}
|
||||
|
||||
// seaparate validation for file type
|
||||
$rules = [
|
||||
'new_img.*' => 'mimes:jpg,png'
|
||||
|
|
@ -162,10 +166,11 @@ class OfferForm extends ComponentBase
|
|||
|
||||
$attachedProduct = $this->fillProduct($data,$attachedProduct);
|
||||
|
||||
// add images to completely new product
|
||||
foreach($data['new_img'] as $key => $img) {
|
||||
$attachedProduct->images = $img;
|
||||
$attachedProduct->save();
|
||||
if(isset($data['new_img'])) {
|
||||
foreach($data['new_img'] as $key => $img) {
|
||||
$attachedProduct->images = $img;
|
||||
$attachedProduct->save();
|
||||
}
|
||||
}
|
||||
|
||||
$this->page['fee'] = Settings::getValue('fee');
|
||||
|
|
@ -199,6 +204,24 @@ class OfferForm extends ComponentBase
|
|||
}
|
||||
}
|
||||
|
||||
// after deleting a photo go the second form_step
|
||||
public function onImageDelete() {
|
||||
// dd(Input::get('product_image_id'));
|
||||
$product = Product::find(Input::get('being_edited_product_id'));
|
||||
|
||||
$product->images()->find(Input::get('product_image_id'))->delete();
|
||||
|
||||
$this->page['measures'] = Measure::all();
|
||||
$this->page['paymentTerms'] = Term::where('type','payment')->get();
|
||||
$this->page['deliveryTerms'] = Term::where('type','delivery')->get();
|
||||
$this->page['currencies'] = Currency::all();
|
||||
$this->page['product'] = $product;
|
||||
|
||||
return [
|
||||
'#form-steps' => $this->renderPartial('@second_step_form')
|
||||
];
|
||||
}
|
||||
|
||||
protected function validateFileType($data, $rules) {
|
||||
$validator = Validator::make($data, $rules);
|
||||
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@
|
|||
<span data-validate-for="description_tm" style="color: red;"></span>
|
||||
</div>
|
||||
|
||||
<span data-validate-for="new_img" style="color: red;"></span>
|
||||
<span data-validate-for="no_images" style="color: red;"></span>
|
||||
<span data-validate-for="new_img_size_error" style="color: red;"></span>
|
||||
<span data-validate-for="new_img_type_error" style="color: red;"></span>
|
||||
<div class="post_upload_box">
|
||||
|
|
@ -140,11 +140,12 @@
|
|||
{% if product.images[i] %}
|
||||
<div class="post_upload_img">
|
||||
<img src="{{ product.images[i].thumb(347,150,{'mode':'crop'}) }}" alt="photo">
|
||||
<input type="hidden" name="old_imgs[{{i}}]">
|
||||
<input type="hidden" name="old_img[{{i}}]">
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="post_input">
|
||||
{% if not product.images[i] %}
|
||||
<label>Загрузить фото #{{i+1}} <span>*</span></label>
|
||||
<div class="upload_group">
|
||||
<label for="file-{{i}}">Загрузить файл</label>
|
||||
|
|
@ -159,10 +160,13 @@
|
|||
/>
|
||||
</div>
|
||||
</div>
|
||||
{% if product.images[i] %}
|
||||
<div class="select_delete" onclick="removeFunction()">
|
||||
{% else %}
|
||||
<a href="#"
|
||||
data-request="onImageDelete"
|
||||
data-request-data="being_edited_product_id: {{product.id}}, product_image_id: {{product.images[i].id}}"
|
||||
class="select_delete delete-btn">
|
||||
<img src="{{'assets/images/svg/red-close.svg'|theme}}" alt="">
|
||||
</div>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -186,3 +190,4 @@
|
|||
|
||||
<script src="{{ 'assets/js/custom-file-input.js'|theme }}"></script>
|
||||
<script src="{{ 'assets/js/scrollTopOnSteps.js'|theme }}"></script>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue