context

Useful global variables and methods.

class Context()
Context.__createAnnotatorSelectionTooltipDiv()

Creates the selection tooltip

Context._test_set_locale()
Context.addUTCTimezoneToISO8601(e)

[A utility function to convert backend DateTime data (ISO 8601 String) into ISO 8601 String with UTC Timezone] TODO: This function was taken from app/js/models/social.js. Refactor to use this Ctx version throughout codebase.

Arguments
  • e (string) –

Returns

ISO 8601 String with UTC Timezone

Return type

String

Context.appendExtraURLParams(url, params)

Helper function to add query string to a URL

Arguments
  • url (string) – The URL to append query string to

  • 'Array' ].<object> params ([) – An array of key-value objects denoting the query string, raw (unencoded)

Returns

The query string updated URL

Return type

string

Context.canUseExpertInterface()

Checks user permissions to use expert interface

Return type

Boolean

Context.clearModal()

Utility method to close the modal view properly

Context.deanonymizationCifInUrl()
Context.debug()
Context.DEPRECATEDgetMessageListConfigFromStorage()

Returns the Object with mesagelistconfig in the localStorage

Return type

Object

Context.DEPRECATEDsetMessageListConfigToStorage(messageListConfig)

Adds a panel in the localStorage

Arguments
  • messageListConfig (Object) – The Object with mesagelistconfig in the localStorage

Returns

The Object with mesagelistconfig in the localStorage

Return type

Object

Context.escapeHtml(str)

Use the browser’s built-in functionality to quickly and safely escape the string

Arguments
  • str (String) – returns {String}

Context.extractId(str)

Given the string in the format “local:ModelName/{id}” returns the id

Arguments
  • str (string) –

Return type

string

Context.format(string, arguments)

Format string function

Arguments
  • string (string) –

  • 'Array' ].<string> arguments ([) –

Return type

string

Context.formatAvatarUrl(userID[, size=44])

Returns the avatar’s url formatted with the given size

Arguments
  • userID (number) – The user’s ID

  • size (number) – The avatar size

Return type

string

Context.formatDate(date, format)

Format date

Arguments
  • date (Date|timestamp) –

  • format (string) – app.dateFormat The format

Return type

string

Context.getAbsoluteURLFromDiscussionRelativeURL(url)

Returns an absolute url from a discussion relative url

Arguments
  • url (String) –

Return type

String

Context.getAbsoluteURLFromRelativeURL(url)

Returns an absolute url from a relative url

Arguments
  • url (String) –

Return type

String

Context.getApiUrl(url)

Formats the url to the current api url

Arguments
  • url (string) –

Returns

The url formatted

Return type

string

Context.getApiV2DiscussionUrl(url)

Formats the url to the current api v2 discussion url

Arguments
  • url (string) –

Returns

The url formatted

Return type

string

Context.getApiV2Url(url)

Formats the url to the current api v2 url

Arguments
  • url (string) –

Returns

The url formatted

Return type

string

Context.getCookieItem()
Context.getCsrfToken()

Returns the CRSF token

Return type

String

Context.getCurrentInterfaceType()

Returns the user interface the user wants simple or expert

Returns

interface_id, one of SIMPLE, EXPERT

Return type

String

Context.getCurrentSynthesisDraftPromise()

Returns the draft of the current synthesis

Return type

Object

Context.getCurrentTime()

Return the current time

Return type

timestamp

Context.getCurrentUser()

Returns the connected user

Return type

Object

Context.getCurrentUserFacebookAccountId()

This assumes that the there is a 1:1 relationship between the AgentProfile (the user) and FacebookAccount the fbAccount if it exists, else returns undefined]

Returns

the @id of the account if any

Return type

String|undefined

Context.getCurrentUserId()

Returns the id of the connected user

Return type

String

Context.getDiscussionId()

Returns the id of the current discussion

Return type

String

Context.getDiscussionSlug()

Returns the slug of the discussion (name of discussion in the url)

Return type

String

Context.getDraggedAnnotation()

Returns the dragged annotation

Return type

String

Context.getDraggedSegment()

Returns the current segment

Returns

segment

Return type

String

Context.getErrorMessageFromAjaxError(response)

Returns an error message when an Ajax request fail

Arguments
  • response (Object) –

Return type

string

Context.getJsonFromScriptTag(id)

Returns embed JSON in the html.

Arguments
  • id (selector) –

Return type

Json

Context.getLocale()

Returns the current locale

Return type

String

Context.getLocaleToLanguageNameCache()

Cache of the locale to locale-name. The language names will be sent from the back-end in the language of the interface. Found from the <script id=”locale-names”></script> eg. Interface language: EN eg. {“fr”: “French”} eg. Interface language FR eg. {“fr”: “Francais”}

Returns

Language cache

Return type

object

Context.getLoginURL()

Returns the URL of the login page

Return type

String

Context.getMessageViewStyleDefById(messageViewStyleId)

get a view style definition by id

Arguments
  • messageViewStyleId (string) –

Return type

messageViewStyle

Context.getNiceDate(date, precise, forbid_future)

Returns a fancy date (ex: a few seconds ago) without time

Arguments
  • date (Date) –

  • precise (Boolean) –

  • forbid_future

Return type

string

Context.getNiceDateTime(date, precise, with_time, forbid_future)

Returns a fancy date (ex: a few seconds ago), or a formatted precise date if precise is true

Arguments
  • date (Date) –

  • precise (Boolean) –

  • with_time (Boolean) –

  • forbid_future

Return type

string

Context.getOEmbedUrl()

Returns the URL of the OEmbed server

Return type

String

Context.getPermissionTokenPromise(json, id)

Write Json in the html

Arguments
  • json (Json) –

  • id (Selector) –

Context.getPostIdFromAnnotation(annotation)

Returns the Post related to the given annotation

Arguments
  • annotation (Annotation) –

Return type

Message

Context.getPreferences()

Returns discussion preferences.

Return type

Object

Context.getReadableDateTime(date)

Returns a nicely formatted date, but not an approximative expression (i.e. not “a few seconds ago”)

Arguments
  • date (Date) –

Return type

string

Context.getRelativeURLFromDiscussionRelativeURL(url)

Returns an relative url from a discussion relative url

Arguments
  • url (String) –

Return type

String

Context.getRoleNames()

Returns names of roles

Return type

Array

Context.getSocketUrl()

Returns the URL of the socket

Return type

String

Context.getTooltipsContainerSelector()
Context.getTranslationLocaleToLanguageNameCache()

Cache of the locale to locale-name available in the discussion. The language names will be sent from the back-end in the language of the interface. Found from the <script id=”translation-locale-names”></script> eg. Interface language: EN eg. {“fr”: “French”} eg. Interface language FR eg. {“fr”: “Francais”}

Returns

Language cache

Return type

object

Context.getTranslationServiceData()

Cache of the translation service data stored in the <script id=”translation-service-data”></script>

Return type

Json

Context.getUrlFromUri(str)

Returns an formatted url

Arguments
  • str (string) –

Return type

string

Context.hasTranslationService()

Checks if translation service is available

Return type

Boolean

Context.htmlEntities(html)

Convert all applicable characters to HTML entities

Arguments
  • html (string) – returns {String}

Context.init()
Context.initMomentJsLocale()

Moment.j only has specific locales, for example, it has fr-ca, but no fr-fr. If you add new language support, you need to add it here. Supported locales for moment.js can be found in /assembl/static/js/node_modules/moment/locale/

Context.initTooltips(elm)

init tool tips on each element with data-toggle attribute

Arguments
  • elm (Selector) –

Context.isApplicationUnderProduction()
Return type

Boolean

Context.isApplicationUnderTest()
Return type

Boolean

Context.isElementInViewport()

Checks if an element is in the viewport

Return type

Boolean

Context.isInFullscreen()

Checks if there is a panel in fullscreen mode ( i.e.: there is only one open )

Return type

boolean

Context.isSmallScreen()

Checks if user use a small screen

Return type

Boolean

Context.isUserConnected()

Checks if user is connected

Return type

Boolean

Context.loadCsrfToken()

fallback: synchronously load app.csrfToken

Returns

csrfToken

Return type

String

Context.loadTemplate(id)

Returns a template from an script tag

Arguments
  • id (string) – The id of the script tag

Returns

The Underscore.js _.template return

Return type

function

Context.makeLinksShowOembedOnHover()
Context.manageLastCurrentUser()
Context.onAjaxError()
Context.onDropdownClick()
Context.openTargetInModal()

Opens the clicked element with data attribute in modal Display options are retrieved from evt.currentTarget attributes or from the “options” parameter (Object used as an associative array). Modal can be dynamically resized once the iframe is loaded, or on demand.

Return type

Boolean

Context.openTargetInPopOver()

Opens the clicked element with data attribute in pop over

Return type

Boolean

Context.popDraggedIdea()

Returns the dragged idea

Returns

idea

Return type

Object

Context.popoverAfterEmbed()

“this” has to be the popover div: $(“#popover-oembed”)

Context.removeCurrentlyDisplayedTooltips()

Removes all tooltips from the screen. Without this, active tooltips (those currently displayed) will be left dangling if the trigger element is removed from the dom.

Context.saveCurrentAnnotationAsExtract()

Saves the current annotation if there is any

Context.setApplicationUnderProduction()
Context.setApplicationUnderTest()
Context.setCsrfToken(token)

Set the CRSF token

Arguments
  • token (string) –

Context.setCurrentModalView()

Utility method used to identify to Ctx the View object that is the modal. Useful for closing the model in any part of the code instead of the context of where the Modal was instantiated.

Context.setCurrentSynthesisDraftId()

Set the id of the synthesis draft

Context.setCurrentUser(user)

Set useful informations about the connected user for analytics

Arguments
  • user (objet) –

Context.setDraggedAnnotation(annotation, annotatorEditor)

Set the current annotation

Arguments
  • annotation

  • annotatorEditor

Context.setDraggedSegment(segment)

Set the current segment

Arguments
  • segment

Context.setInterfaceType(interface_id)

Set the user interface the user wants

Arguments
  • interface_id (String) – one of SIMPLE, EXPERT

Context.setLocale(locale)

Set the locale in a cookie and reload page

Arguments
  • locale (String) – key

Context.showDragbox(ev, text)

Shows the dragbox when user starts dragging an element This method is designed to be called in a dragstart event listener.

Arguments
  • ev (Event) – The event object

  • text (string) – The text to be shown in the .dragbox

Context.showTargetBySegment(segment)

Shows the segment source in the better way related to the source e.g.: If it is an email, opens it, if it is a webpage, open in another window …

Arguments
  • segment (Segment) –

Context.stripHtml(html)

This removes (rather than escape) all html tags

Arguments
  • html (string) –

Returns

The new string without html tags

Return type

string

Context.unescapeHtml(escapedStr)

UNSAFE with unsafe strings; only use on previously-escaped ones!

Arguments
  • escapedStr (String) –

Return type

String

Context.updateCurrentUser()

Get from database up-to-date information about current logged-in user.

Context.writeJsonToScriptTag(json, id)

Write Json in the html

Arguments
  • json (Json) –

  • id (Selector) –