Skip to content

Commit a3edcbe

Browse files
author
kozhevnikov
committed
remove kartik-fileinput compocer dependency
1 parent b4caeee commit a3edcbe

File tree

4 files changed

+37
-35
lines changed

4 files changed

+37
-35
lines changed

OnmotionAsset.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ class OnmotionAsset extends AssetBundle
1818
{
1919
public $sourcePath = __DIR__ . '/assets';
2020
public $css = [
21+
'bootstrap-fileinput-4.3.1/css/fileinput.min.css',
2122
'css/onmotion-gallery.css',
2223
];
2324
public $js = [
25+
'bootstrap-fileinput-4.3.1/js/plugins/canvas-to-blob.min.js',
26+
'bootstrap-fileinput-4.3.1/js/fileinput.min.js',
2427
'js/onmotion-bootstrap-modal.js',
2528
'js/onmotion-gallery.js',
2629
];

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
"require": {
1616
"yiisoft/yii2": ">=2.0.1",
1717
"bower-asset/blueimp-gallery": ">=v2.17.0",
18-
"onmotion/yii2-helpers": "*",
19-
"kartik-v/bootstrap-fileinput": ">=4.3.1",
20-
"kartik-v/yii2-widget-fileinput": ">=v1.0.5"
18+
"onmotion/yii2-helpers": "*"
2119
},
2220
"autoload": {
2321
"psr-4": {

controllers/DefaultController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,13 @@ public function actionIndex()
5858

5959
public function actionFileupload()
6060
{
61-
6261
$extraData = Yii::$app->request->post();
6362
$model = new GalleryPhoto();
6463

6564
if (!empty($_FILES) && $_FILES['image']['error'][0] == 0) {
6665
$imageTmpName = $_FILES["image"]["tmp_name"][0];
6766
$pathinfo = pathinfo($_FILES["image"]["name"][0]);
68-
$imageName = uniqid() . '.' . $pathinfo['extension'];
67+
$imageName = $pathinfo['filename'] . uniqid() . '.' . $pathinfo['extension'];
6968
list($width, $height) = getimagesize($imageTmpName);
7069

7170
$ratio = $width / $height;
@@ -156,7 +155,7 @@ public function actionFileupload()
156155
public function actionView($id)
157156
{
158157

159-
$photos = GalleryPhoto::find()->where(['gallery_id' => $id])->all();
158+
$photos = GalleryPhoto::find()->where(['gallery_id' => $id])->orderBy('name')->all();
160159

161160
return $this->render('view', [
162161
'model' => $this->findModel($id),

views/default/view.php

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -81,35 +81,8 @@
8181
'items' => [
8282
[
8383
'label' => 'Upload photo',
84-
'content' => FileInput::widget([
85-
'name' => 'image[]',
86-
'language' => 'en',
87-
'options' => [
88-
'multiple' => true,
89-
],
90-
'pluginOptions' => [
91-
'showPreview' => false,
92-
'uploadUrl' => Url::to(['fileupload']),
93-
'uploadExtraData' => [
94-
'gallery_id' => $model->gallery_id,
95-
'gallery_name' => $model->name,
96-
],
97-
'allowedFileExtensions' => ["jpg", "png"],
98-
'allowedFileTypes' => ['image'],
99-
'maxFileCount' => 1000,
100-
'maxFileSize' => 15000,
101-
'messageOptions' => [
102-
'class' => 'alert-warning-message'
103-
],
104-
'elErrorContainer' => '#errorBlock'
105-
],
106-
'pluginEvents' => [
107-
'fileuploaded' => NEW \yii\web\JsExpression("function(e){location.reload();}")
108-
],
109-
]) .
110-
' <div id="errorBlock">
111-
<ul class="alert-warning-message"></ul>
112-
</div>'
84+
'content' => '<input id="input-1a" name="image[]" type="file" class="file-loading" multiple>' .
85+
' <div id="errorBlock"><ul class="alert-warning-message"></ul></div>'
11386
]
11487
],
11588
'options' => [
@@ -151,4 +124,33 @@
151124
echo Html::tag('div', Html::tag('span', '100', ['class' => 'sr-only']), ['class'=>"progress-bar progress-bar-striped active", 'role'=>"progressbar",
152125
'aria-valuenow'=>"100", 'aria-valuemin'=>"0", 'aria-valuemax'=>"100", 'style'=>"width:100%"]);
153126
echo Html::endTag('div');
127+
128+
129+
$this->registerJs(<<<JS
130+
131+
$(document).on('ready', function() {
132+
$("#input-1a").fileinput({
133+
showPreview: false,
134+
uploadUrl: 'fileupload',
135+
uploadAsync: true,
136+
uploadExtraData: {
137+
'gallery_id': "$model->gallery_id",
138+
'gallery_name': "$model->name",
139+
},
140+
maxFileCount: 1000,
141+
allowedFileTypes: ['image'],
142+
allowedFileExtensions: ['jpg', 'png'],
143+
messageOptions: {
144+
'class': 'alert-warning-message'
145+
},
146+
elErrorContainer: '#errorBlock'
147+
148+
});
149+
150+
$('#input-1a').on('fileuploaded', function(event, data, previewId, index) {
151+
location.reload();
152+
});
153+
});
154+
JS
155+
);
154156
?>

0 commit comments

Comments
 (0)