Skip to content

Commit d5633eb

Browse files
author
Leonix
committed
Site app v.3.1.0
1 parent 52d0a19 commit d5633eb

File tree

116 files changed

+4637
-2443
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+4637
-2443
lines changed

wa-apps/site/css/site.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wa-apps/site/img/magic-wand.png

6.42 KB
Loading

wa-apps/site/js/compiled/site.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wa-apps/site/js/editor/form/FormConstructor.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ var FormConstructor = ( function($) {
247247
'ButtonSizeToggle': that.vue_components['component-toggle'],
248248
},
249249
},
250-
"ColumnsGroup": {
250+
"OldColumnsGroup": {
251251
props: {
252252
group_config: { type: Object },
253253
block_data: { type: Object, default: {} },
@@ -300,7 +300,7 @@ var FormConstructor = ( function($) {
300300
}
301301
}
302302
},
303-
"NewColumnsGroup": {
303+
"ColumnsGroup": {
304304
props: {
305305
group_config: { type: Object },
306306
block_data: { type: Object, default: {} },
@@ -315,7 +315,7 @@ var FormConstructor = ( function($) {
315315
$.each(self.columns_nodes, function(i, node) {
316316
const column_id = $(node).attr('data-block-id');
317317
const column_data = $.wa.editor.block_storage.getData(column_id);
318-
columns_data.push(column_data.new_column);
318+
columns_data.push(column_data.column);
319319
if (column_data?.indestructible) indestructible_cols = true;
320320
});
321321
let arr_options = that.storage_data['ColumnsGroup'].values;
@@ -343,7 +343,7 @@ var FormConstructor = ( function($) {
343343

344344
let column_id = that.$target_wrapper.find('.js-seq-wrapper').eq(0).find('> .seq-child').eq(column_num - 1).data('block-id');
345345
const column_data = $.wa.editor.block_storage.getData(column_id);
346-
column_data.new_column = temp_active_options.join(' ');
346+
column_data.column = temp_active_options.join(' ');
347347
self.columns_data[column_num - 1] = temp_active_options.join(' ');
348348
$.wa.editor.saveBlockData(column_id, column_data, {
349349
notify_editor_inside_iframe: true,
@@ -367,7 +367,7 @@ var FormConstructor = ( function($) {
367367
$block_wrapper.css('opacity', 0.5)
368368
let column_data = {}
369369
if (column_id) column_data = { duplicate_block_id: column_id };
370-
else column_data = { parent_block_id: $block_wrapper.data('block-id'), type_name: 'site.NewColumn_' };
370+
else column_data = { parent_block_id: $block_wrapper.data('block-id'), type_name: 'site.Column_' };
371371
$.post('?module=editor&action=addBlock', column_data).then(function(new_parent_block_html) {
372372
$block_wrapper.replaceWith(new_parent_block_html);
373373
});

wa-apps/site/js/site.js

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ var that = $.site = {
2727

2828
navigate: function(absolute_url) {
2929
if (this.opts.content_router_mode == 'xhr' && isRoutableViaXHR(absolute_url)) {
30-
this.loadContent(absolute_url);
31-
return;
30+
return this.loadContent(absolute_url);
3231
}
3332

3433
location.href = absolute_url;
@@ -83,6 +82,9 @@ var that = $.site = {
8382
xhr: xhr
8483
}]);
8584
}).fail(function(data) {
85+
if (data.statusText === 'abort') {
86+
return;
87+
}
8688
console.log('Unable to load content for URL', url);
8789
if (data?.responseText?.match && data.responseText.match(/waException|id="Trace"/)) {
8890
console.log(data.responseText);
@@ -120,6 +122,28 @@ var that = $.site = {
120122
if (this.opts.is_debug) {
121123
console.log.apply(null, arguments);
122124
}
125+
},
126+
127+
confirmUnsaved: function(opts) {
128+
opts = opts || { onSave: () => null, onLeave: () => null };
129+
130+
$.waDialog({
131+
html: this.opts.templates['unsaved_form_dialog'],
132+
onOpen ($d, d) {
133+
d.$block.find('.js-save-button').on('click', () => {
134+
if (typeof opts.onSave === 'function') {
135+
opts.onSave();
136+
}
137+
d.close();
138+
});
139+
d.$block.find('.js-leave-button').on('click', () => {
140+
if (typeof opts.onLeave === 'function') {
141+
opts.onLeave();
142+
}
143+
d.close();
144+
});
145+
}
146+
})
123147
}
124148
};
125149

@@ -220,13 +244,13 @@ function isRoutableViaXHR(absolute_url) {
220244
return true;
221245
}
222246

223-
// Props
224247
$.site.helper = {
248+
// Props
225249
xhr: null,
226-
};
227-
// Methods
228-
$.site.helper = {
229-
loadSortableJS: () => {
250+
xhr_id: null,
251+
252+
// Methods
253+
loadSortableJS: function () {
230254
const dfd = $.Deferred();
231255

232256
const $script = $("#wa-header-js"),
@@ -254,21 +278,31 @@ $.site.helper = {
254278
return dfd.promise();
255279
},
256280
// Cancels previous request
257-
preventDupeRequest: (fn) => {
258-
if ($.site.helper.xhr && typeof $.site.helper.xhr.abort === 'function') {
259-
$.site.helper.xhr.abort();
260-
$.site.helper.xhr = null;
281+
preventDupeRequest: function (fn, id) {
282+
id = typeof id === 'undefined' ? null : id;
283+
284+
if (id !== null) {
285+
if (id === this.xhr_id && this.xhr) {
286+
return;
287+
}
288+
this.xhr_id = id;
289+
}
290+
if (this.xhr && typeof this.xhr.abort === 'function') {
291+
this.xhr.abort();
292+
this.xhr = null;
261293
}
262294

263295
$('#wa-app').trigger('wa_before_load');
264296

265297
const resolver = () => {
266-
$.site.helper.xhr = null;
298+
this.xhr = null;
267299
$('#wa-app').trigger('wa_loaded');
268300
};
269-
$.site.helper.xhr = fn(resolver);
270-
if ($.site.helper.xhr && typeof $.site.helper.xhr.always === 'function') {
271-
$.site.helper.xhr.always(resolver);
301+
302+
this.xhr = fn(resolver);
303+
304+
if (this.xhr && typeof this.xhr.always === 'function') {
305+
this.xhr.always(resolver);
272306
}
273307
}
274308
};

wa-apps/site/lib/actions/backend/siteBackend.controller.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ public function execute13()
3636

3737
public function execute20()
3838
{
39+
if (null === waRequest::get('list')) {
40+
$last_domain_id = $this->getUser()->getSettings('site', 'last_domain_id');
41+
if ($last_domain_id) {
42+
43+
if (isset(siteHelper::getDomains()[$last_domain_id])) {
44+
$this->redirect('?module=map&action=overview&domain_id='.$last_domain_id);
45+
}
46+
}
47+
}
3948
$this->executeAction(new siteBackendDomainsAction());
4049
$this->setLayout(new siteBackendLayout());
4150
}

wa-apps/site/lib/actions/backend/siteBackendDomains.action.php

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,123 @@ public function execute()
88
{
99
$domains = siteHelper::getDomains(true);
1010

11-
foreach ($domains as $n => $d) {
11+
foreach ($domains as &$d) {
12+
if (empty($d['is_alias'])) {
13+
foreach (wa()->getRouting()->getRoutes($d['name']) as $r) {
14+
if ($r['url'] === '*' && isset($r['redirect']) && substr($r['redirect'], 0, 4) === 'http') {
15+
$d['redirect'] = $r['redirect'];
16+
break;
17+
}
18+
}
19+
}
20+
1221
$path = wa()->getDataPath(null, true).'/data/'.$d['name'].'/favicon.ico';
1322
if (file_exists($path)) {
14-
$domains[$n]['favicon'] = wa()->getDataUrl('data/'.$d['name'].'/favicon.ico', true);
23+
$d['favicon'] = wa()->getDataUrl('data/'.$d['name'].'/favicon.ico', true);
1524
} else {
1625
$path = 'http'.(waRequest::isHttps() ? 's' : '').'://'.$d['name'].'/favicon.ico';
1726
if (file_exists($path)) {
18-
$domains[$n]['favicon'] = $path;
27+
$d['favicon'] = $path;
1928
}
2029
}
2130
}
2231

32+
$this->prepareData($domains);
33+
34+
$sort_types = [
35+
'created:asc' => [
36+
'title' => _w('Added later'),
37+
'icon' => '<i class="fas fa-sort-amount-down-alt"></i>'
38+
],
39+
'created:desc' => [
40+
'title' => _w('Added earlier'),
41+
'icon' => '<i class="fas fa-sort-amount-down"></i>'
42+
],
43+
'name:asc' => [
44+
'title' => _w('By name A–Z'),
45+
'icon' => '<i class="fas fa-sort-alpha-down"></i>'
46+
],
47+
'name:desc' => [
48+
'title' => _w('By name Z–A'),
49+
'icon' => '<i class="fas fa-sort-alpha-down-alt"></i>'
50+
],
51+
];
52+
53+
$sort = $this->getSort();
54+
if (empty($sort_types[$sort])) {
55+
$sort = 'created:desc';
56+
}
57+
58+
$this->makeSort($domains, $sort);
2359

2460
$this->view->assign([
25-
'domains' => $domains,
61+
'domains' => $domains,
62+
'is_list_view' => wa()->getUser()->getSettings('site', 'list_view') == 1,
63+
'sort' => $sort,
64+
'sort_types' => $sort_types,
2665
]);
2766
}
67+
68+
private function prepareData(&$domains)
69+
{
70+
foreach ($domains as &$d) {
71+
$d['title'] = str_replace('www.', '', waIdna::dec($d['title']));
72+
}
73+
}
74+
75+
private function makeSort(&$domains, $sort_by)
76+
{
77+
$sortName = function ($asc = true) {
78+
return function ($a, $b) use ($asc) {
79+
$a = $a['title'];
80+
$b = $b['title'];
81+
$n = ($asc ? 1 : -1);
82+
83+
$has_num_a = preg_match('/^\d+/i', $a);
84+
$has_num_b = preg_match('/^\d+/i', $b);
85+
if ($has_num_a || $has_num_b) {
86+
if ($has_num_a && !$has_num_b) {
87+
return -1 * $n;
88+
} elseif (!$has_num_a && $has_num_b) {
89+
return 1 * $n;
90+
}
91+
}
92+
93+
$begins_in_cyrillic_a = preg_match('/^[а-яА-ЯЁё]/u', $a);
94+
$begins_in_cyrillic_b = preg_match('/^[а-яА-ЯЁё]/u', $b);
95+
if ($begins_in_cyrillic_a && !$begins_in_cyrillic_b) {
96+
return -1 * $n;
97+
} elseif (!$begins_in_cyrillic_a && $begins_in_cyrillic_b) {
98+
return 1 * $n;
99+
}
100+
101+
return strcmp($a, $b) * $n;
102+
};
103+
};
104+
105+
switch ($sort_by) {
106+
case 'name:asc':
107+
uasort($domains, $sortName(true));
108+
break;
109+
case 'name:desc':
110+
uasort($domains, $sortName(false));
111+
break;
112+
case 'created:asc':
113+
$domains = array_reverse($domains, true);
114+
break;
115+
}
116+
}
117+
118+
private function getSort()
119+
{
120+
$setting_key = 'domain_list_sort';
121+
$sort = waRequest::get('sort');
122+
if ($sort) {
123+
$this->getUser()->setSettings('site', $setting_key, $sort);
124+
} else {
125+
$sort = $this->getUser()->getSettings('site', $setting_key);
126+
}
127+
128+
return $sort;
129+
}
28130
}

wa-apps/site/lib/actions/legacy/blocks/siteBlocksSave.controller.php renamed to wa-apps/site/lib/actions/blocks/siteBlocksSave.controller.php

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public function execute()
77
$id = waRequest::get('id');
88
$info = waRequest::post('info');
99

10-
if (!preg_match('/^[a-z0-9\._]+$/i', $info['id'])) {
10+
if (!preg_match('/^[a-z0-9\._-]+$/i', $info['id'])) {
1111
$this->errors = array(
1212
_w('Only Latin letters, numbers, and the underscore character are allowed.'),
1313
'input[name="info[id]"]'
@@ -17,58 +17,39 @@ public function execute()
1717

1818
$model = new siteBlockModel();
1919

20-
if ($id) {
21-
try {
20+
try {
21+
if ($id) {
2222
$model->updateById($id, $info);
2323
$this->logAction('block_edit');
2424
if ($id != $info['id']) {
2525
$info['old_id'] = $id;
2626
}
2727
$this->response($info);
28-
} catch (waDbException $wde) {
29-
if ($wde->getCode() === 1406) {
30-
$this->errors = [
31-
_w('The block is too large. Reduce it or create several blocks instead of one.'),
32-
'input[name="info[content]"]'
33-
];
34-
} else {
35-
throw $wde;
36-
}
37-
} catch (Exception $e) {
38-
if ($model->getById($info['id'])) {
39-
$this->errors = array(
40-
sprintf(_w('Block with id “%s” already exists.'), $info['id']),
41-
'input[name="info[id]"]'
42-
);
43-
} else {
44-
throw $e;
45-
}
46-
}
47-
} else {
48-
try {
28+
} else {
4929
$model->add($info);
5030
$this->logAction('block_add');
5131
$this->response($info);
52-
} catch (waDbException $wde) {
53-
if ($wde->getCode() === 1406) {
32+
}
33+
} catch (waDbException $wde) {
34+
switch ($wde->getCode()) {
35+
case 1062:
36+
$this->errors = [
37+
sprintf(_w('Block with id “%s” already exists.'), $info['id']),
38+
'input[name="info[id]"]',
39+
1
40+
];
41+
break;
42+
case 1406:
5443
$this->errors = [
5544
_w('The block is too large. Reduce it or create several blocks instead of one.'),
5645
'input[name="info[content]"]'
5746
];
58-
} else {
47+
break;
48+
default:
5949
throw $wde;
60-
}
61-
} catch (Exception $e) {
62-
if ($model->getById($info['id'])) {
63-
$this->errors = array(
64-
sprintf(_w('Block with id “%s” already exists.'), $info['id']),
65-
'input[name="info[id]"]'
66-
);
67-
} else {
68-
throw $e;
69-
}
7050
}
7151
}
52+
7253
if ($this->getConfig()->getOption('cache_time')) {
7354
waSystem::getInstance()->getView()->clearAllCache();
7455
}

0 commit comments

Comments
 (0)