This repository was archived by the owner on May 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathjson-entry-aside.php
63 lines (53 loc) · 1.86 KB
/
json-entry-aside.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<style>
.uk-modal-json .uk-modal-dialog {
height: 85%;
}
.button-update {
float: right;
}
</style>
<div class="uk-modal uk-modal-json uk-height-viewport">
<div class="uk-modal-dialog uk-modal-dialog-large">
<a href="" class="uk-modal-close uk-close"></a>
<strong>@lang('JSON Data')</strong>
<button if="{permissions.jsonEdit}" onclick="{updateData}" class="button-update uk-button uk-button-small uk-button-primary uk-margin-right">
<i class="uk-icon-save"></i> @lang('Update')</button>
<div class="uk-margin uk-flex uk-flex-middle" if="{entry}">
<codemirror ref="codemirrorjson" syntax="json"></codemirror>
</div>
</div>
</div>
<script>
var $this = this;
this.on('mount', function() {
$this.modal = UIkit.modal(App.$('.uk-modal-json', this.root), {modal:true});
$this.update();
});
this.showEntryJson = function() {
$this.modal.show();
editor = $this.refs.codemirrorjson.editor;
editor.setValue(JSON.stringify($this.entry, null, 2), true);
editor.setOption("readOnly", !$this.permissions.jsonEdit);
editor.setSize($this.modal.dialog[0].clientWidth - 50, $this.modal.dialog[0].clientHeight - 70);
editor.refresh();
$this.trigger('ready');
}
this.updateData = function(e) {
editor = $this.refs.codemirrorjson.editor;
try {
_.extend($this.entry, JSON.parse(editor.getValue()));
$this.update();
var elements = App.$('cp-field[type=wysiwyg]');
elements.each(function(key, el) {
var id = App.$(el).find('textarea').first().attr('id');
tinyMCE.get(id).setContent(el.$getValue());
});
$this.modal.hide();
$this.update();
App.ui.notify(App.i18n.get("Collection entry data updated! Save to persist changes."));
} catch(e) {
App.ui.notify(App.i18n.get("Cannot update! Invalid json structure"), "danger");
return;
}
}
</script>