1 | <?php |
||
2 | |||
3 | /** @var Apps\Model\Admin\Content\FormContentUpdate $model */ |
||
4 | /** @var \Ffcms\Templex\Template\Template $this */ |
||
5 | |||
6 | use Apps\ActiveRecord\ContentCategory; |
||
7 | use Ffcms\Core\Helper\Text; |
||
8 | use Ffcms\Core\Helper\Type\Str; |
||
9 | use Ffcms\Templex\Helper\Html\Dom; |
||
10 | use Ffcms\Templex\Url\Url; |
||
11 | |||
12 | $this->layout('_layouts/default', [ |
||
13 | 'title' => __('Content edit'), |
||
14 | 'breadcrumbs' => [ |
||
15 | Url::to('main/index') => __('Main'), |
||
16 | Url::to('application/index') => __('Applications'), |
||
17 | Url::to('content/index') => __('Contents'), |
||
18 | __('Content manage') |
||
19 | ] |
||
20 | ]); |
||
21 | ?> |
||
22 | |||
23 | <?php $this->push('css') ?> |
||
24 | <!-- jquery ui plugin --> |
||
25 | <link rel="stylesheet" href="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/jquery-ui-dist/jquery-ui.min.css" /> |
||
26 | <!-- dropzone css plugin --> |
||
27 | <link rel="stylesheet" href="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/dropzone/dist/dropzone.css" /> |
||
28 | <style> |
||
29 | .dropzone { |
||
30 | border: 2px dashed #0087F7; |
||
31 | border-radius: 5px; |
||
32 | background: white; |
||
33 | } |
||
34 | </style> |
||
35 | <!-- selectize plugin --> |
||
36 | <link rel="stylesheet" href="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/selectize/dist/css/selectize.default.css" /> |
||
37 | <?php $this->stop() ?> |
||
38 | |||
39 | <?php $this->start('body') ?> |
||
40 | <?= $this->insert('content/_tabs') ?> |
||
41 | <h1><?= __('Content manage') ?></h1> |
||
42 | <?php |
||
43 | $form = $this->form($model); |
||
44 | echo $form->start(); |
||
45 | |||
46 | $menu = $this->bootstrap()->nav('ul', ['class' => 'nav-tabs']) |
||
47 | ->menu(['text' => __('General'), 'tab' => function() use ($form) { |
||
48 | /** @var \Ffcms\Templex\Template\Template $this */ |
||
49 | $langMenu = $this->bootstrap()->nav('ul', ['class' => 'nav-tabs']); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
50 | foreach (\App::$Properties->get('languages') as $lang) { |
||
51 | $langMenu->menu([ |
||
52 | 'text' => Str::upperCase($lang), |
||
53 | 'tab' => function() use ($form, $lang) { |
||
54 | return $form->fieldset()->text('title.' . $lang, null, __('Fill the title of the content for current language locale')) . |
||
55 | '<strong>' . __('Content text') . '</strong><br />' . |
||
56 | $form->field()->textarea('text.' . $lang, ['class' => 'form-control wysiwyg', 'rows' => 7]); |
||
57 | }, |
||
58 | 'tabActive' => $lang === \App::$Request->getLanguage() |
||
59 | ]); |
||
60 | } |
||
61 | return (new Dom())->div(function() use ($langMenu) { |
||
62 | return $langMenu->display(); |
||
63 | }, ['class' => 'nav-border']); |
||
64 | }, 'tabActive' => true]) |
||
65 | ->menu(['text' => __('Properties'), 'tab' => function() use ($form) { |
||
66 | /** @var \Ffcms\Templex\Template\Template $this */ |
||
67 | $langMenu = $this->bootstrap()->nav('ul', ['class' => 'nav-tabs']); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
68 | $context = $form->fieldset()->text('path', null, __('Slug of URL pathway for this content item')) |
||
69 | . $form->fieldset()->select('categoryId', ['options' => ContentCategory::getSortedCategories(), 'optionsKey' => true, 'multiple' => null], __('Select content category')); |
||
70 | |||
71 | foreach (\App::$Properties->get('languages') as $lang) { |
||
72 | $langMenu->menu([ |
||
73 | 'text' => Str::upperCase($lang), |
||
74 | 'tab' => function() use ($form, $lang) { |
||
75 | return $form->fieldset()->text('metaTitle.' . $lang, null, __('Set meta title for content page (displayed in browser head). Recommended length: 50-70 chars')). |
||
76 | $form->fieldset()->text('metaKeywords.' . $lang, ['class' => 'tag-selectize'], __('Set meta keywords for this content (for search engine crawlers) separated by comma')). |
||
77 | $form->fieldset()->text('metaTitle.' . $lang, null, __('Set meta description for this content (for search engine crawlers). Recommended length: 200-250 chars')); |
||
78 | }, |
||
79 | 'tabActive' => $lang === \App::$Request->getLanguage() |
||
80 | ]); |
||
81 | } |
||
82 | |||
83 | // compile context with lang menu |
||
84 | $context .= $langMenu->display(); |
||
85 | |||
86 | return $context; |
||
87 | }]) |
||
88 | ->menu(['text' => __('Gallery'), 'tab' => function() use ($form) { |
||
89 | return '<div class="row" id="gallery-files"></div> |
||
90 | <div class="row"> |
||
91 | <div class="col-md-8"> |
||
92 | <div class="dropzone dropzone-previews" id="ffcms-dropzone"></div> |
||
93 | </div> |
||
94 | <div class="col-md-4"> |
||
95 | ' . $form->fieldset()->select('poster', ['options' => [__('Not selected...')]], __("Select image from gallery as a poster for this content")) . ' |
||
96 | </div> |
||
97 | </div><br/><br/>'; |
||
98 | }]) |
||
99 | ->menu(['text' => __('Other'), 'tab' => function() use ($form, $model) { |
||
100 | return $form->fieldset()->boolean('display', null, __('Can users view this content or only available for administrators?')) . |
||
101 | $form->fieldset()->boolean('important', null, __('Make this material important and stack it on top of all news?')) . |
||
102 | $form->fieldset()->text('createdAt', ['class' => 'form-control datepick'], __('Set the date of creation or leave empty for current date')) . |
||
103 | $form->fieldset()->select('authorId', ['options' => $model->getUserIdName(), 'optionsKey' => true, 'class' => 'selectize-option'], __('Enter author user_id or leave empty to set current user as author')) . |
||
104 | $form->fieldset()->text('source', null, __('Set source URL if this content is copied from another website')) . |
||
105 | $form->fieldset()->text('addRating', null, __('Add or reduce this content rating. Example: 5 gives +5 to total rating, -5 gives -5 to total')); |
||
106 | }]); |
||
107 | |||
108 | if (!$model->isNew()) { |
||
109 | $menu->menu(['text' => __('Comments'), 'tab' => function() use ($form, $model) { |
||
0 ignored issues
–
show
|
|||
110 | /** @var \Ffcms\Templex\Template\Template $this */ |
||
111 | $comments = $model->getComments(); |
||
112 | |||
113 | if (!$comments || $comments->count() < 1) { |
||
114 | return $this->bootstrap()->alert('warning', __('No comments found')); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
115 | } |
||
116 | |||
117 | $table = $this->table(['class' => 'table table-striped']) |
||
118 | ->head([ |
||
119 | ['text' => '#'], |
||
120 | ['text' => __('Message')], |
||
121 | ['text' => __('Answers')], |
||
122 | ['text' => __('Author')], |
||
123 | ['text' => __('Actions'), 'properties' => ['class' => 'text-center']] |
||
124 | ]); |
||
125 | |||
126 | foreach ($comments as $comment) { |
||
127 | $table->row([ |
||
128 | ['text' => $comment->id], |
||
129 | ['text' => Text::snippet(\App::$Security->strip_tags($comment->message), 100)], |
||
130 | ['text' => $comment->getAnswerCount()], |
||
131 | ['text' => Url::a(['user/update', [$comment->user_id]], ($comment->user->profile->nick ?? 'id' . $comment->user->id)), 'html' => true], |
||
132 | ['text' => $this->bootstrap()->btngroup(['class' => 'btn-group btn-group-sm']) |
||
133 | ->add('<i class="fa fa-pencil"></i>', ['comments/read', [$comment->id]], ['html' => true, 'class' => 'btn btn-primary', 'target' => '_blank']) |
||
134 | ->add('<i class="fa fa-trash-o"></i>', ['comments/delete', ['comment', $comment->id]], ['html' => true, 'class' => 'btn btn-danger', 'target' => '_blank']) |
||
135 | ->display(),'properties' => ['class' => 'text-center'], 'html' => true |
||
136 | ] |
||
137 | ]); |
||
138 | } |
||
139 | return (new Dom())->div(function() use ($table){ |
||
140 | return $table->display(); |
||
141 | }, ['class' => 'table-responsive']); |
||
142 | }]); |
||
143 | } |
||
144 | |||
145 | echo $menu->display(); |
||
146 | echo $form->button()->submit(__('Save'), ['class' => 'btn btn-primary mt-2']); |
||
147 | |||
148 | ?> |
||
149 | |||
150 | <?= $form->field()->hidden('galleryFreeId') ?> |
||
151 | |||
152 | <?= $form->stop() ?> |
||
153 | |||
154 | <?php $this->stop() ?> |
||
155 | |||
156 | <?php $this->push('javascript') ?> |
||
157 | <!-- jquery ui plugin --> |
||
158 | <script src="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/jquery-ui-dist/jquery-ui.min.js"></script> |
||
159 | <!-- tinymce plugin --> |
||
160 | <?= \Widgets\Tinymce\Tinymce::widget([ |
||
161 | 'config' => 'full' |
||
162 | ]); ?> |
||
163 | <!-- dropzone js plugin --> |
||
164 | <script src="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/dropzone/dist/dropzone.js"></script> |
||
165 | <script>Dropzone.autoDiscover = false</script> |
||
166 | <!-- jquery datepicker plugin (over jquery-ui) --> |
||
167 | <script src="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/jquery-datepicker/jquery-datepicker.js"></script> |
||
168 | <!-- selectize plugin --> |
||
169 | <script src="<?= \App::$Alias->scriptUrl ?>/vendor/phpffcms/ffcms-assets/node_modules/selectize/dist/js/standalone/selectize.min.js"></script> |
||
170 | <script> |
||
171 | $(document).ready(function(){ |
||
172 | var isChanged = false; |
||
173 | var pathChanged = false; |
||
174 | $('.datepick').datepicker({ |
||
175 | dateFormat: 'dd.mm.yy' |
||
176 | }); |
||
177 | |||
178 | // prevent send submit if authorization session gone away |
||
179 | $('form').submit(function () { |
||
180 | var valid = false; |
||
181 | $.ajax({ |
||
182 | async: false, |
||
183 | type: 'GET', |
||
184 | url: script_url + '/api/user/auth?lang=' + script_lang, |
||
185 | contentType: 'json', |
||
186 | success: function(r){ |
||
187 | if (r.status === 1) |
||
188 | valid = true; |
||
189 | } |
||
190 | }); |
||
191 | if (!valid) { |
||
192 | alert('<?= __('Attention! Your session is deprecated. You need to make auth in new window!') ?>'); |
||
193 | return false; |
||
194 | } |
||
195 | window.onbeforeunload = null; |
||
196 | }); |
||
197 | |||
198 | // listen form(input,textarea) changes event |
||
199 | $('input,textarea').keyup(function(){ |
||
200 | isChanged = true; |
||
201 | }); |
||
202 | |||
203 | // check if changes is saved before page is unloaded |
||
204 | window.onbeforeunload = function(e){ |
||
205 | if (!isChanged) |
||
206 | return; |
||
207 | |||
208 | var msg = 'Page not saved! Please save changes!'; |
||
209 | if (typeof e === 'undefined') |
||
210 | e = window.event; |
||
211 | |||
212 | if (e) |
||
213 | e.returnValue = msg; |
||
214 | return msg; |
||
215 | }; |
||
216 | |||
217 | // dropzone gallery file listing and display |
||
218 | // gallery file listing |
||
219 | $.getJSON(script_url + "/api/content/gallerylist/<?= $model->galleryFreeId ?>?lang=" + script_lang, function (data) { |
||
220 | if (data.status !== 1) |
||
221 | return; |
||
222 | $.each(data.files, function (index, file) { |
||
223 | var DropzoneObj = Dropzone.forElement('#ffcms-dropzone'); |
||
224 | var FileObj = {name: file.name, size: file.size, status: Dropzone.ADDED, accepted: true}; |
||
225 | DropzoneObj.emit('addedfile', FileObj); |
||
226 | DropzoneObj.emit('thumbnail', FileObj, file.thumbnailUrl); |
||
227 | DropzoneObj.emit('complete', FileObj); |
||
228 | DropzoneObj.files.push(FileObj); |
||
229 | |||
230 | var option = '<option value="' + file.name + '">' + file.name + '</option>'; |
||
231 | if (file.name == '<?= $model->poster ?>') { |
||
232 | option = '<option value="' + file.name + '" selected>' + file.name + '</option>'; |
||
233 | } |
||
234 | $('#FormContentUpdate-poster').append(option); |
||
235 | }); |
||
236 | }); |
||
237 | |||
238 | // manual initialize & configure dropzone file uploading |
||
239 | var DropzoneFiles = []; |
||
240 | $('#ffcms-dropzone').dropzone({ |
||
241 | url: script_url + '/api/content/galleryupload/<?= $model->galleryFreeId ?>?lang=' + script_lang, |
||
242 | dictDefaultMessage: '<?= __('Drop files here to upload in gallery') . '<br />' . __('(or click here)') ?>', |
||
243 | acceptedFiles: ".jpeg,.jpg,.png,.gif,.webp", |
||
244 | addRemoveLinks: true, |
||
245 | removedfile: function (file) { // file remove click, lets try to remove file from server & make visual changes |
||
246 | var serverFile = DropzoneFiles[file.name] != null ? DropzoneFiles[file.name] : file.name; |
||
247 | $.getJSON(script_url + "/api/content/gallerydelete/<?= $model->galleryFreeId ?>?lang=" + script_lang + "&file=" + serverFile, function (data) { |
||
248 | if (data.status === 1) { |
||
249 | if (file.previewElement != null) |
||
250 | return file.previewElement.parentNode.removeChild(file.previewElement); |
||
251 | } |
||
252 | return void 0; |
||
253 | }); |
||
254 | }, |
||
255 | success: function (file, response) { // upload is successful done. Lets try to check server response & build file list |
||
256 | // save files as array ClientFileName => ServerFileName |
||
257 | if (response.status !== 1) { |
||
258 | if (file.previewElement != null) |
||
259 | file.previewElement.parentNode.removeChild(file.previewElement); |
||
260 | alert(response.message); |
||
261 | return; |
||
262 | } |
||
263 | DropzoneFiles[file.name] = response.file.name; |
||
264 | // add to <select> poster options |
||
265 | var posterOption = '<option value="' + response.file.name + '">' + file.name + '</option>'; |
||
266 | $('#FormContentUpdate-poster').append(posterOption); |
||
267 | //console.log('Client file: [' + file.name + ']/Server file:[' + response.file.name + ']'); |
||
268 | } |
||
269 | }); |
||
270 | |||
271 | // prepare selectize features |
||
272 | $('.tag-selectize').selectize({ |
||
273 | delimiter: ',', |
||
274 | persist: false, |
||
275 | create: function (input) { |
||
276 | return { |
||
277 | value: input, |
||
278 | text: input |
||
279 | } |
||
280 | } |
||
281 | |||
282 | }); |
||
283 | $('.selectize-option').selectize({ |
||
284 | sortField: 'text' |
||
285 | }); |
||
286 | |||
287 | }); |
||
288 | </script> |
||
289 | <?php $this->stop() ?> |
||
290 |