Skip to content

Commit

Permalink
Added new feature, "Repeat Num Element", lets you designate and eleme…
Browse files Browse the repository at this point in the history
…nt on a form which controls how many repeats a group has. Changing the value will add/remove repeats to specified number.
  • Loading branch information
cheesegrits committed Mar 14, 2017
1 parent 7e61254 commit ec71c0e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 4 deletions.
Expand Up @@ -1099,6 +1099,8 @@ COM_FABRIK_REPEAT_GROUP_MIN_DESC="The minimum number of repeats allowed for this
COM_FABRIK_REPEAT_GROUP_MIN_LABEL="Repeat min"
COM_FABRIK_REPEAT_GROUP_MINMAX_ERR_DESC="OPTIONAL - if specified, an alert will be shown if the user attempt to add too many (or not enough) groups. Can use custom language strings. Placeholders {min} and {max} will be replaced with applicable values."
COM_FABRIK_REPEAT_GROUP_MINMAX_ERR_LABEL="Min/Max Err Msg"
COM_FABRIK_REPEAT_GROUP_REPEAT_NUM_ELEMENT_LABEL="Repeat Num Element"
COM_FABRIK_REPEAT_GROUP_REPEAT_NUM_ELEMENT_DESC="Optional - you can choose an element which will be used to specify the number of repeats for this group. When the value is changed, the form will automatically add/remove groups to the specified number."
COM_FABRIK_REPEAT_GROUP_TMPL_LIST="list"
COM_FABRIK_REPEAT_GROUP_TMPL_TABLE="table"
COM_FABRIK_REPEAT_INTRO_DESC="Introductory text shown before each repeat group. Can use placeholders. The {i} placeholder is replaced with the current repeat group number."
Expand Down
7 changes: 7 additions & 0 deletions administrator/components/com_fabrik/models/forms/group.xml
Expand Up @@ -144,6 +144,13 @@
description="COM_FABRIK_REPEAT_GROUP_MIN_DESC"
size="2"/>

<field name="repeat_num_element"
type="listfields"
valueformat="tableelement"
label="COM_FABRIK_REPEAT_GROUP_REPEAT_NUM_ELEMENT_LABEL"
description="COM_FABRIK_REPEAT_GROUP_REPEAT_NUM_ELEMENT_LABEL"
/>

<field name="repeat_error_message"
type="text"
label="COM_FABRIK_REPEAT_GROUP_MINMAX_ERR_LABEL"
Expand Down
1 change: 1 addition & 0 deletions components/com_fabrik/models/group.php
Expand Up @@ -1035,6 +1035,7 @@ public function getGroupProperties(&$formModel)
$group->displaystate = ($group->canRepeat == 1 && $formModel->isEditable()) ? 1 : 0;
$group->maxRepeat = (int) $params->get('repeat_max');
$group->minRepeat = $params->get('repeat_min', '') === '' ? 1 : (int) $params->get('repeat_min', '');
$group->numRepeatElement = $params->get('repeat_num_element', '');
$group->showMaxRepeats = $params->get('show_repeat_max', '0') == '1';
$group->minMaxErrMsg = $params->get('repeat_error_message', '');
$group->minMaxErrMsg = FText::_($group->minMaxErrMsg);
Expand Down
2 changes: 2 additions & 0 deletions components/com_fabrik/views/form/view.base.php
Expand Up @@ -790,6 +790,7 @@ protected function jsOpts()
$hidden[$g->id] = $g->startHidden;
$maxRepeat[$g->id] = $g->maxRepeat;
$minRepeat[$g->id] = $g->minRepeat;
$numRepeatEls[$g->id] = FabrikString::safeColNameToArrayKey($g->numRepeatElement);
$showMaxRepeats[$g->id] = $g->showMaxRepeats;
$minMaxErrMsg[$g->id] = $g->minMaxErrMsg;
}
Expand All @@ -799,6 +800,7 @@ protected function jsOpts()
$opts->minRepeat = $minRepeat;
$opts->showMaxRepeats = $showMaxRepeats;
$opts->minMaxErrMsg = $minMaxErrMsg;
$opts->numRepeatEls = $numRepeatEls;

// $$$ hugh adding these so calc element can easily find joined and repeated join groups
// when it needs to add observe events ... don't ask ... LOL!
Expand Down
4 changes: 2 additions & 2 deletions media/com_fabrik/js/dist/form.js

Large diffs are not rendered by default.

45 changes: 43 additions & 2 deletions media/com_fabrik/js/form.js
Expand Up @@ -61,7 +61,7 @@ define(['jquery', 'fab/encoder', 'fab/fabrik', 'lib/debounce/jquery.ba-throttle-
this.duplicatedGroups = $H({});
this.addingOrDeletingGroup = false;
this.addedGroups = [];

this.watchRepeatNumsDone = false;
this.fx = {};
this.fx.elements = [];
this.fx.hidden = [];
Expand Down Expand Up @@ -150,9 +150,32 @@ define(['jquery', 'fab/encoder', 'fab/fabrik', 'lib/debounce/jquery.ba-throttle-
this.watchGoBackButton();
}


this.watchPrintButton();
this.watchPdfButton();
this.watchTabs();
this.watchRepeatNums();
},

watchRepeatNums: function () {
Fabrik.addEvent('fabrik.form.elements.added', function (form) {
if (form.id === this.id && !this.watchRepeatNumsDone) {
Object.each(this.options.numRepeatEls, function (name, key) {
if (name !== '') {
var el = this.formElements.get(name);
if (el) {
el.addNewEventAux(el.getChangeEvent(), function(event) {
var v = el.getValue();
this.options.minRepeat[key] = v.toInt();
this.options.maxRepeat[key] = v.toInt();
this.duplicateGroupsToMin();
}.bind(this, el, key));
}
}
}.bind(form));
this.watchRepeatNumsDone = true;
}
}.bind(this));
},

/**
Expand Down Expand Up @@ -1673,7 +1696,9 @@ define(['jquery', 'fab/encoder', 'fab/fabrik', 'lib/debounce/jquery.ba-throttle-
}

var min = this.options.minRepeat[groupId].toInt();
var max = this.options.maxRepeat[groupId].toInt();
var group = this.form.getElement('#group' + groupId);
var subGroup;

/**
* $$$ hugh - added ability to override min count
Expand All @@ -1688,7 +1713,7 @@ define(['jquery', 'fab/encoder', 'fab/fabrik', 'lib/debounce/jquery.ba-throttle-
// Create mock event
deleteButton = this.form.getElement('#group' + groupId + ' .deleteGroup');
deleteEvent = typeOf(deleteButton) !== 'null' ? new Event.Mock(deleteButton, 'click') : false;
var subGroup = group.getElement('.fabrikSubGroup');
subGroup = group.getElement('.fabrikSubGroup');
// Remove only group
this.deleteGroup(deleteEvent, group, subGroup);

Expand All @@ -1705,6 +1730,18 @@ define(['jquery', 'fab/encoder', 'fab/fabrik', 'lib/debounce/jquery.ba-throttle-
}
}
}
else if (max > 0 && repeat_rows > max) {
// Delete groups
for (i = repeat_rows; i > max; i--) {
var b = jQuery(this.form.getElements('#group' + groupId + ' .deleteGroup')).last()[0];
var del_btn = jQuery(b).find('[data-role=fabrik_delete_group]')[0];
subGroup = jQuery(group.getElements('.fabrikSubGroup')).last()[0];
if (typeOf(del_btn) !== 'null') {
var del_e = new Event.Mock(del_btn, 'click');
this.deleteGroup(del_e, group, subGroup);
}
}
}

this.setRepeatGroupIntro(group, groupId);
}.bind(this));
Expand Down Expand Up @@ -1758,10 +1795,12 @@ define(['jquery', 'fab/encoder', 'fab/fabrik', 'lib/debounce/jquery.ba-throttle-
Fabrik.fireEvent('fabrik.form.group.delete.end', [this, e, i, delIndex]);
} else {
var toel = subGroup.getPrevious();
/*
var myFx = new Fx.Tween(subGroup, {
'property': 'opacity',
duration : 300,
onComplete: function () {
*/
if (subgroups.length > 1) {
subGroup.dispose();
}
Expand Down Expand Up @@ -1793,8 +1832,10 @@ define(['jquery', 'fab/encoder', 'fab/fabrik', 'lib/debounce/jquery.ba-throttle-
}
}.bind(this));
Fabrik.fireEvent('fabrik.form.group.delete.end', [this, e, i, delIndex]);
/*
}.bind(this)
}).start(1, 0);
*/
if (toel) {
// Only scroll the window if the previous element is not visible
var win_scroll = document.id(window).getScroll().y;
Expand Down

0 comments on commit ec71c0e

Please sign in to comment.