'wcf.poll.button.removeOption': '{lang}wcf.poll.button.removeOption{/lang}'
});
- new WCF.Poll.Management('pollOptionContainer', [ {implode from=$pollOptions item=pollOption}{ optionID: {@$pollOption[optionID]}, optionValue: '{$pollOption[optionValue]}' }{/implode} ]);
+ new WCF.Poll.Management('pollOptionContainer', [ {implode from=$pollOptions item=pollOption}{ optionID: {@$pollOption[optionID]}, optionValue: '{$pollOption[optionValue]}' }{/implode} ], {@POLL_MAX_OPTIONS});
});
//]]>
</script>
*/
_container: null,
+ /**
+ * number of options
+ * @var integer
+ */
+ _count: 0,
+
/**
* width for input-elements
* @var integer
*/
_inputSize: 0,
+ /**
+ * maximum allowed number of options
+ * @var integer
+ */
+ _maxOptions: 0,
+
/**
* Initializes the WCF.Poll.Management class.
*
* @param string containerID
* @param array<object> optionList
+ * @param integer maxOptions
*/
- init: function(containerID, optionList) {
+ init: function(containerID, optionList, maxOptions) {
+ this._count = 0;
+ this._maxOptions = maxOptions || -1;
this._container = $('#' + containerID).children('ol:eq(0)');
if (!this._container.length) {
console.debug("[WCF.Poll.Management] Invalid container id given, aborting.");
}
WCF.DOMNodeInsertedHandler.execute();
+
+ this._count++;
+ if (this._count === this._maxOptions) {
+ this._container.find('span.jsAddOption').removeClass('pointer').addClass('disabled');
+ }
},
/**
* @param object event
*/
_addOption: function(event) {
+ if (this._count === this._maxOptions) {
+ return false;
+ }
+
var $listItem = $(event.currentTarget).parents('li');
this._createOption(undefined, undefined, $listItem);
_removeOption: function(event) {
$(event.currentTarget).parents('li').remove();
+ this._count--;
+ this._container.find('span.jsAddOption').addClass('pointer').removeClass('disabled');
+
if (this._container.children('li').length == 0) {
this._createOption();
}
throw new UserInputException('pollOptions');
}
+ // too many options provided, discard superfluous options
+ if ($count > POLL_MAX_OPTIONS) {
+ $this->pollOptions = array_slice($this->pollOptions, 0, POLL_MAX_OPTIONS);
+ }
+
// less options available than allowed
if ($count < $this->pollData['maxVotes']) {
throw new UserInputException('pollMaxVotes', 'notValid');