Javascript#

Utils#

removeObjectFromList(obj, objList)#

Remove an object from a list.

Arguments:
  • obj – Object to remove

  • objList – List of objects

Returns:

A new list without obj.

pad(n)#

Helper function to pad dates

Date#

dateStr(date)#

Get date string in YYYY-MM-DD format

dateFromValue(dateId, timeId)#

Get a datetime object taking date and time from two different DOM elements.

Arguments:
  • dateId – Id of the DOM element containing the date value

  • timeId – Id of the DOM element containing the time value

Returns:

Date

dateIsoFromValue(dateId, timeId)#

Return the same as dataFromValue but in ISO format.

Arguments:
  • dateId – Id of the DOM element containing the date value

  • timeId – Id of the DOM element containing the time value

Returns:

string

timeStr(date)#

Get hour:minutes string HH:00 format

datetimeStr(date)#

Compose dateStr and timeStr.

Returns:

string

dateNoTime(date)#

Return the part of the date without any time

dateInRange(date, range, useTime)#

Return true if the date is within a given range.

Arguments:
  • date – Input date.

  • range – Object containing start and end attributes.

  • useTime – Whether to use the time or not for the comparison.

Returns:

boolean

rangesOverlap(event1, event2, useTime)#

Check if two events overlap using dateInRange function.

Events should have start and end attributes.

rangeInside(event1, event2, useTime)#

Check if one event is contained in the other using dateInRange function.

Events should have start and end attributes.

Debugging#

printObject(obj, label)#

Print object’s attributes to the console.

Arguments:
  • obj – Input object to be printed.

  • label – Label to print before the object.

printArray(array, label)#

Print an Array to console.

Arguments:
  • array – Array to be printed.

  • label – Label to print before the array.

printList(objList, label)#

Print a list of objects to console.

Arguments:
  • objList – Input list of objects to be printed.

  • label – Label to print before the object.

printDict(objDict, label)#

Print dictionary to the console.

Arguments:
  • objDict – Input dictionary to be printed.

  • label – Label to print before the object.

Dialogs#

showMessage(title, msg)#

Show a dialog with a message.

Arguments:
  • title – Title of the dialog.

  • msg – Message to display.

showError(msg)#

Show a dialog with an ERROR message.

Arguments:
  • msg – Message to display, prepended by ‘ERROR’.

confirm(heading, question, cancelButtonTxt, okButtonTxt, callback)#

Display a confirmation dialog that could trigger a callback function.

Arguments:
  • heading – Title to be display for the confirmation.

  • question – Question asked for confirmation. (e.g. Do want to delete this entry?)

  • cancelButtonTxt – Label for the Cancel-Button (e.g. Cancel)

  • okButtonTxt – Label for the OK-Button (e.g. OK, Update, Delete)

  • callback – Callback function to be called if the OK-Button is called

notImplemented(msg)#

Show a ‘NOT IMPLEMENTED’ message dialog.

AJAX#

get_ajax_html(url, params)#

Make an AJAX request to the server expecting html result.

Arguments:
  • url – URL to make the AJAX request

  • params – dictionary with parameters to retrieve the content.

get_ajax_content(content_id, params)#

Make an AJAX request to the server, getting the URL for a specific content page

Arguments:
  • content_id – content id that will be requested from the server

  • params – dictionary with extra parameters to retrieve the content.

load_html_from_ajax(container_id:, ajaxContent:)#

Make an AJAX request to retrieve some content and set it as the HTML of the container.

Arguments:
  • container_id: – Container that will receive the HTML content

  • ajaxContent: – already created AJAX content

show_modal_from_ajax(container_id:, ajaxContent:)#

Make an AJAX request to retrieve some content and set it as the HTML of a modal dialog.

Arguments:
  • container_id: – ID of the element used as modal

  • ajaxContent: – already created AJAX content

send_ajax_json(url:, attrs:, done:, fail:)#

Make an AJAX request sending json data to some url in the server

Arguments:
  • url: – URL to send the ajax request

  • attrs: – json data to send

  • done: – callback when the request is done

  • fail: – callback when the request failed

send_ajax_form(url:, formData:, done:, fail:)#

Make an AJAX request sending data from a web Form as json to some url in the server

Arguments:
  • url: – URL to send the ajax request

  • formData: – Form data to be sent as JSON

  • done: – callback when the request is done

  • fail: – callback when the request failed

ajax_request_done(jsonResponse, expectedKey)#

Generic handler for when an AJAX request is done.

Arguments:
  • jsonResponse – response from the request.

  • expectedKey – expected key in the response if it succeeded

ajax_request_failed(jqXHR, textStatus)#

Generic handler for when an AJAX request failed.