aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/static/intereditor.js
diff options
context:
space:
mode:
Diffstat (limited to 'internal/admin/static/intereditor.js')
-rw-r--r--internal/admin/static/intereditor.js50
1 files changed, 46 insertions, 4 deletions
diff --git a/internal/admin/static/intereditor.js b/internal/admin/static/intereditor.js
index a17225a..c4f16e7 100644
--- a/internal/admin/static/intereditor.js
+++ b/internal/admin/static/intereditor.js
@@ -326,10 +326,11 @@ function ie_collectLeaf(el) {
// ── Render condition ──
-function ie_renderCond(condObj, secId, idx, secPath, kind) {
+function ie_renderCond(condObj, secId, idx, secPath, kind, opts) {
kind = kind || 'entry';
var h = '';
var isGroup = condObj && (condObj.all_of || condObj.any_of);
+ var rootChildCount = isGroup ? (condObj.all_of || condObj.any_of || []).length : 0;
if (condObj && typeof condObj === 'object') {
var condTitleText = '';
if (kind && kind.indexOf('step-') === 0) {
@@ -343,13 +344,13 @@ function ie_renderCond(condObj, secId, idx, secPath, kind) {
h += ie_renderGroup(condObj, secId, secPath, idx, '', kind);
h += '</div>';
}
- var showAddbar = !isGroup;
+ var showAddbar = !isGroup || (opts && opts.alwaysOuterAddbar && rootChildCount === 0);
if (showAddbar) {
h += '<div class="ie-cond-addbar">';
IE_COND_TYPES.forEach(function(ct) {
- h += '<button class="btn btn-sm ie-add-btn ie-cond-add-leaf" onclick="ie_addLeaf(\'' + escAttr(secId) + '\',\'' + escAttr(secPath) + '\',' + idx + ',\'' + escAttr(kind) + '\',\'\',\'' + ct.type + '\')">+ ' + esc(ct.label) + '</button>';
+ h += '<button class="btn btn-sm ie-add-btn ie-cond-add-leaf" onclick="ie_addOuterLeaf(\'' + escAttr(secId) + '\',\'' + escAttr(secPath) + '\',' + idx + ',\'' + escAttr(kind) + '\',\'' + ct.type + '\')">+ ' + esc(ct.label) + '</button>';
});
- h += '<button class="btn btn-sm ie-add-btn ie-cond-add-grp" onclick="ie_addGroup(\'' + escAttr(secId) + '\',\'' + escAttr(secPath) + '\',' + idx + ',\'' + escAttr(kind) + '\',\'\')">+ Group</button>';
+ h += '<button class="btn btn-sm ie-add-btn ie-cond-add-grp" onclick="ie_addOuterGroup(\'' + escAttr(secId) + '\',\'' + escAttr(secPath) + '\',' + idx + ',\'' + escAttr(kind) + '\')">+ Group</button>';
h += '</div>';
}
return h;
@@ -881,6 +882,47 @@ function ie_addGroup(secId, secPath, idx, kind, groupPath) {
window._ieRenderOnly();
}
+function ie_addOuterLeaf(secId, secPath, idx, kind, leafType) {
+ var ed = window._editorData;
+ if (!ed) return;
+ _ie_syncCond(ed, secId, secPath, idx, kind);
+ var cond = _ie_getCond(ed, secPath, idx, kind);
+
+ var leaf = {};
+ leaf[leafType] = (leafType === 'min_credits' || leafType === 'room') ? 0 : '';
+
+ var newCond;
+ if (!cond) {
+ newCond = leaf;
+ } else {
+ newCond = {all_of: [cond, leaf]};
+ }
+
+ _ie_setCond(ed, secPath, idx, kind, newCond);
+ ced_syncDOMToData(ed);
+ window._ieRenderOnly();
+}
+
+function ie_addOuterGroup(secId, secPath, idx, kind) {
+ var ed = window._editorData;
+ if (!ed) return;
+ _ie_syncCond(ed, secId, secPath, idx, kind);
+ var cond = _ie_getCond(ed, secPath, idx, kind);
+
+ var newSub = {all_of: []};
+
+ var newCond;
+ if (!cond) {
+ newCond = newSub;
+ } else {
+ newCond = {all_of: [cond, newSub]};
+ }
+
+ _ie_setCond(ed, secPath, idx, kind, newCond);
+ ced_syncDOMToData(ed);
+ window._ieRenderOnly();
+}
+
function ie_toggleCondMode(secId, secPath, idx, kind, groupPath) {
var ed = window._editorData;
if (!ed) return;