summaryrefslogtreecommitdiff
path: root/platform/www/lib/plugins/bureaucracy/script
diff options
context:
space:
mode:
Diffstat (limited to 'platform/www/lib/plugins/bureaucracy/script')
-rwxr-xr-xplatform/www/lib/plugins/bureaucracy/script/datepicker.js11
-rw-r--r--platform/www/lib/plugins/bureaucracy/script/fieldsets.js84
-rwxr-xr-xplatform/www/lib/plugins/bureaucracy/script/user.js90
3 files changed, 185 insertions, 0 deletions
diff --git a/platform/www/lib/plugins/bureaucracy/script/datepicker.js b/platform/www/lib/plugins/bureaucracy/script/datepicker.js
new file mode 100755
index 0000000..1716cbe
--- /dev/null
+++ b/platform/www/lib/plugins/bureaucracy/script/datepicker.js
@@ -0,0 +1,11 @@
+/**
+ * Init datepicker for all date fields
+ */
+
+jQuery(function(){
+ jQuery('.bureaucracy__plugin .datepicker').datepicker({
+ dateFormat: "yy-mm-dd",
+ changeMonth: true,
+ changeYear: true
+ });
+}); \ No newline at end of file
diff --git a/platform/www/lib/plugins/bureaucracy/script/fieldsets.js b/platform/www/lib/plugins/bureaucracy/script/fieldsets.js
new file mode 100644
index 0000000..2a3c12d
--- /dev/null
+++ b/platform/www/lib/plugins/bureaucracy/script/fieldsets.js
@@ -0,0 +1,84 @@
+/**
+ * Handle display of dependent, i. e. optional fieldsets
+ *
+ * Fieldsets may be defined as dependent on the value of a certain input. In
+ * this case they contain a p element with the CSS class “bureaucracy_depends”.
+ * This p element holds a span with the class “bureaucracy_depends_fname”
+ * and optionally another span with “bureaucracy_depends_fvalue”. They
+ * specify the target input (fname) and the target value for which the fieldset
+ * is to be shown.
+ *
+ * This function adds onchange handlers to the relevant inputs for showing and
+ * heading the respective fieldsets.
+ *
+ * @author Adrian Lang <dokuwiki@cosmocode.de>
+ **/
+
+jQuery(function () {
+
+ jQuery('form.bureaucracy__plugin').each(function () {
+
+ //show/hide fieldset and trigger depending children
+ function updateFieldset(input) {
+ jQuery.each(jQuery(input).data('dparray'), function (i, dp) {
+ var showOrHide =
+ input.parentNode.parentNode.style.display !== 'none' && // input/checkbox is displayed AND
+ ((input.checked === dp.tval) || // ( checkbox is checked
+ (input.type !== 'checkbox' && (dp.tval === true && input.value !== '')) || // OR no checkbox, but input is set
+ input.value === dp.tval); // OR input === dp.tval )
+
+ dp.fset.toggle(showOrHide);
+
+ dp.fset.find('input,select')
+ .each(function () {
+ //toggle required attribute
+ var $inputelem = jQuery(this);
+ if($inputelem.hasClass('required')) {
+ if(showOrHide) {
+ $inputelem.attr('required', 'required');
+ } else {
+ $inputelem.removeAttr('required')
+ }
+ }
+ //update dependencies
+ if ($inputelem.data('dparray')) {
+ $inputelem.change();
+ }
+ });
+ });
+ }
+
+ //look for p (with info about controller) in depending fieldsets
+ jQuery('p.bureaucracy_depends', this)
+ .each(function () {
+ //get controller info
+ var fname = jQuery(this).find('span.bureaucracy_depends_fname').html(),
+ fvalue = jQuery(this).find('span.bureaucracy_depends_fvalue');
+ fvalue = (fvalue.length ? fvalue.html() : true);
+
+ //get controller field and add info and change event to the input that controls depending fieldset
+ var fieldsetinfo = {
+ fset: jQuery(this).parent(),
+ tval: fvalue
+ };
+
+ jQuery("label")
+ .has(":first-child:contains('" + fname + "')").first()
+ .find("select,input:last") //yesno field contains first a hidden input
+ .each(function () {
+ if (!jQuery(this).data('dparray')) {
+ jQuery(this).data('dparray', [fieldsetinfo]);
+ } else {
+ jQuery(this).data('dparray').push(fieldsetinfo);
+ }
+ })
+ .bind('change keyup', function () {
+ updateFieldset(this);
+ })
+ .change();
+
+ })
+ .hide(); //hide p.bureaucracy_depends in fieldset
+
+ });
+});
diff --git a/platform/www/lib/plugins/bureaucracy/script/user.js b/platform/www/lib/plugins/bureaucracy/script/user.js
new file mode 100755
index 0000000..9d5d806
--- /dev/null
+++ b/platform/www/lib/plugins/bureaucracy/script/user.js
@@ -0,0 +1,90 @@
+/**
+ * Provides a list of matching user names while user inputs into a userpicker
+ *
+ * @author Adrian Lang <lang@cosmocode.de>
+ * @author Gerrit Uitslag <klapinklapin@gmail.com>
+ */
+jQuery(function () {
+ /**
+ * Ajax request for user suggestions
+ *
+ * @param {Object} request object, with single 'term' property
+ * @param {Function} response callback, argument: the data array to suggest to the user.
+ * @param {Function} getterm callback, argument: the request Object, returns: search term
+ */
+ function ajaxsource(request, response, getterm) {
+ jQuery.getJSON(
+ DOKU_BASE + 'lib/exe/ajax.php', {
+ call: 'bureaucracy_user_field',
+ search: getterm(request)
+ }, function (data) {
+ response(jQuery.map(data, function (name, user) {
+ return {
+ label: name + ' (' + user + ')',
+ value: user
+ }
+ }))
+ }
+ );
+ }
+
+ function split(val) {
+ return val.split(/,\s*/);
+ }
+
+ function extractLast(term) {
+ return split(term).pop();
+ }
+
+
+ /**
+ * pick one user
+ */
+ jQuery(".userpicker").autocomplete({
+ source: function (request, response) {
+ ajaxsource(request, response, function (req) {
+ return req.term
+ })
+ }
+ });
+
+ /**
+ * pick one or more users
+ */
+ jQuery(".userspicker")
+ // don't navigate away from the field on tab when selecting an item
+ .bind("keydown", function (event) {
+ if (event.keyCode === jQuery.ui.keyCode.TAB &&
+ jQuery(this).data("ui-autocomplete").menu.active) {
+ event.preventDefault();
+ }
+ })
+ .autocomplete({
+ minLength: 0,
+ source: function (request, response) {
+ ajaxsource(request, response, function (req) {
+ return extractLast(req.term)
+ })
+ },
+ search: function () {
+ // custom minLength
+ var term = extractLast(this.value);
+ return term.length >= 2;
+ },
+ focus: function () {
+ // prevent value inserted on focus
+ return false;
+ },
+ select: function (event, ui) {
+ var terms = split(this.value);
+ // remove the current input
+ terms.pop();
+ // add the selected item
+ terms.push(ui.item.value);
+ // add placeholder to get the comma-and-space at the end
+ terms.push("");
+ this.value = terms.join(", ");
+ return false;
+ }
+ });
+});