fix

parent ee8c3b3f
*
\ No newline at end of file
...@@ -23,6 +23,7 @@ class BidController extends \common\components\BaseController ...@@ -23,6 +23,7 @@ class BidController extends \common\components\BaseController
'Add' => 'Добавление заявки', 'Add' => 'Добавление заявки',
'Blogadd' => 'Добавление заявки в блог', 'Blogadd' => 'Добавление заявки в блог',
'Upload-files' => 'Загрузка файлов', 'Upload-files' => 'Загрузка файлов',
'Delete-file' => 'Удаление файлов',
]; ];
} }
...@@ -112,12 +113,13 @@ class BidController extends \common\components\BaseController ...@@ -112,12 +113,13 @@ class BidController extends \common\components\BaseController
public function actionUploadFiles() public function actionUploadFiles()
{ {
if(Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON; Yii::$app->response->format = Response::FORMAT_JSON;
$model = new BidFile; $model = new BidFile;
$model->file = UploadedFile::getInstanceByName('file'); $model->file = UploadedFile::getInstanceByName('file');
if($model->file) { if ($model->file) {
if (!file_exists(BidFile::path())) { if (!file_exists(BidFile::path())) {
mkdir(BidFile::path(), 0777, true); mkdir(BidFile::path(), 0777, true);
} }
...@@ -129,5 +131,30 @@ class BidController extends \common\components\BaseController ...@@ -129,5 +131,30 @@ class BidController extends \common\components\BaseController
'filename' => $model->filename 'filename' => $model->filename
]; ];
} }
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
public function actionDeleteFile()
{
if(Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
$filename = Yii::$app->request->post('filename');
if ($filename) {
if (file_exists(BidFile::path() . $filename)) {
unlink(BidFile::path() . $filename);
}
return [
'success' => true
];
}
return [
'success' => false
];
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
} }
} }
...@@ -50,6 +50,10 @@ $('form.bids-form').on('beforeSubmit', function(e) { ...@@ -50,6 +50,10 @@ $('form.bids-form').on('beforeSubmit', function(e) {
form.find('#files-zone').html(''); form.find('#files-zone').html('');
$('.dz-preview.dz-processing').remove(); $('.dz-preview.dz-processing').remove();
$('.file_drop').show();
$('.file_drop_cs').show();
$('.file_upload_bt_cs').show();
$('.file_upload_bt').show();
dataLayer.push({ dataLayer.push({
'event': 'UA_event', 'event': 'UA_event',
......
...@@ -2,8 +2,21 @@ $(document).ready(function() { ...@@ -2,8 +2,21 @@ $(document).ready(function() {
$('.file_upload_bt .file-upload, .file_upload_bt_cs .file-upload_cs, .file_upload_bt_cs .file_drop_cs, .file_upload_bt .file_drop').click(function(){ $('.file_upload_bt .file-upload, .file_upload_bt_cs .file-upload_cs, .file_upload_bt_cs .file_drop_cs, .file_upload_bt .file_drop').click(function(){
$('.dz-clickable').trigger('click'); $('.dz-clickable').trigger('click');
}); });
// Dropzone class:
// var myDropzone = new Dropzone("div#block_upload", {url: "/bids/bid/upload-files", maxFiles: 1}); var toggleButtons = function () {
if(!$('.file-upload_block.dropzone .dz-preview').length) {
$('.file_drop').show();
$('.file_drop_cs').show();
$('.file_upload_bt_cs').show();
$('.file_upload_bt').show();
} else {
$('.file_drop').hide();
$('.file_drop_cs').hide();
$('.file_upload_bt_cs').hide();
$('.file_upload_bt').hide();
}
};
Dropzone.options.blockUpload = { Dropzone.options.blockUpload = {
url: "/bids/bid/upload-files", url: "/bids/bid/upload-files",
maxFiles: 4, maxFiles: 4,
...@@ -14,13 +27,31 @@ $(document).ready(function() { ...@@ -14,13 +27,31 @@ $(document).ready(function() {
dictInvalidFileType: 'Приложенный файл не может быть загружен в целях безопасности. Пожалуйста, приложите файл в другом формате (Word, Pdf, PowerPoint, Excel).', dictInvalidFileType: 'Приложенный файл не может быть загружен в целях безопасности. Пожалуйста, приложите файл в другом формате (Word, Pdf, PowerPoint, Excel).',
dictFileTooBig: 'Максимальный размер файла составляет 15мб.', dictFileTooBig: 'Максимальный размер файла составляет 15мб.',
dictCancelUpload: 'Отменить загрузку', dictCancelUpload: 'Отменить загрузку',
success: function(first, response) success: function(file, response) {
{ file.filename = response.filename;
$('#files-zone').append('<input type="hidden" name="Bid[file][]" value="'+response.filename+'" />'); $('#files-zone').append('<input type="hidden" name="Bid[file][]" value="'+response.filename+'" />');
$('.file_drop').hide(); toggleButtons();
$('.file_drop_cs').hide(); },
$('.file_upload_bt_cs').hide(); removedfile: function (file) {
$('.file_upload_bt').hide(); var $block = $(file.previewElement);
$.ajax({
dataType: 'json',
data: {
filename: file.filename
},
method: 'post',
url: '/bids/bid/delete-file',
success: function (response) {
if(response.success) {
$('#files-zone input[value="'+file.filename+'"]').remove();
$block.remove();
toggleButtons();
}
}
});
}, },
canceled: function () {
toggleButtons();
}
}; };
}); });
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment