diff --git a/app/assets/javascripts/app/index.coffee b/app/assets/javascripts/app/index.coffee index 807944c39..4ec67da63 100644 --- a/app/assets/javascripts/app/index.coffee +++ b/app/assets/javascripts/app/index.coffee @@ -10,200 +10,6 @@ #= require_tree ./lib/app_post class App extends Spine.Controller - helper = - - # define print name helper - P: (object, attributeName, attributes, table = false) -> - App.viewPrint(object, attributeName, attributes, table) - - # define date format helper - date: (time) -> - return '' if !time - - timeObject = new Date(time) - d = App.Utils.formatTime(timeObject.getDate(), 2) - m = App.Utils.formatTime(timeObject.getMonth() + 1, 2) - y = timeObject.getFullYear() - "#{y}-#{m}-#{d}" - - # define datetime format helper - datetime: (time) -> - return '' if !time - - timeObject = new Date(time) - d = App.Utils.formatTime(timeObject.getDate(), 2) - m = App.Utils.formatTime(timeObject.getMonth() + 1, 2) - y = timeObject.getFullYear() - S = App.Utils.formatTime(timeObject.getSeconds(), 2) - M = App.Utils.formatTime(timeObject.getMinutes(), 2) - H = App.Utils.formatTime(timeObject.getHours(), 2) - "#{y}-#{m}-#{d} #{H}:#{M}:#{S}" - - # define decimal format helper - decimal: (data, positions = 2) -> - App.Utils.decimal(data, positions) - - # define time_duration / mm:ss / hh:mm:ss format helper - time_duration: (time) -> - return '' if !time - return '' if isNaN(parseInt(time)) - - # Hours, minutes and seconds - hrs = ~~parseInt((time / 3600)) - mins = ~~parseInt(((time % 3600) / 60)) - secs = parseInt(time % 60) - - # Output like "1:01" or "4:03:59" or "123:03:59" - mins = "0#{mins}" if mins < 10 - secs = "0#{secs}" if secs < 10 - if hrs > 0 - return "#{hrs}:#{mins}:#{secs}" - "#{mins}:#{secs}" - - # define mask helper - # mask an value like 'a***********yz' - M: (item, start = 1, end = 2) -> - return '' if !item - string = '' - end = item.length - end - 1 - for n in [0..item.length-1] - if start <= n && end >= n - string += '*' - else - string += item[n] - string - - # define translation helper - T: (item, args...) -> - App.i18n.translateContent(item, args...) - - # define translation inline helper - Ti: (item, args...) -> - App.i18n.translateInline(item, args...) - - # define translation for date helper - Tdate: (item, args...) -> - App.i18n.translateDate(item, args...) - - # define translation for timestamp helper - Ttimestamp: (item, args...) -> - App.i18n.translateTimestamp(item, args...) - - # define linkify helper - L: (item) -> - if item && typeof item is 'string' - return App.Utils.linkify(item) - item - - # define config helper - C: (key) -> - App.Config.get(key) - - # define session helper - S: (key) -> - App.Session.get(key) - - # define view helper for rendering partial views - V: (name, params) -> - App.view(name)(params) - - # define address line helper - AddressLine: (line) -> - return '' if !line - items = emailAddresses.parseAddressList(line) - - # line was not parsable - return App.Utils.htmlEscape(line) if !items - - # set markup - result = '' - for item in items - if result - result = result + ', ' - if item.name - item.name = item.name - .replace(',', '') - .replace(';', '') - .replace('"', '') - .replace('\'', '') - if item.name.match(/\@|,|;|\^|\+|#|§|\$|%|&|\/|\(|\)|=|\?|\*/) - item.name = "\"#{item.name}\"" - result = "#{result}#{App.Utils.htmlEscape(item.name)} " - if item.address - result = result + " <#{App.Utils.htmlEscape(item.address)}>" - result - - # define file size helper - humanFileSize: (size) -> - App.Utils.humanFileSize(size) - - # define pretty/human time helper - humanTime: (time, escalation = false, cssClass = '') -> - timestamp = App.i18n.translateTimestamp(time) - if escalation - cssClass += ' escalation' - humanTime = App.PrettyDate.humanTime(time, escalation) - "" - - # define icon helper - Icon: (name, className = '') -> - App.Utils.icon(name, className) - - # define richtext helper - RichText: (string) -> - return string if !string - if string.match(/@T\('/) - string = string.replace(/@T\('(.+?)'\)/g, (match, capture) -> - App.i18n.translateContent(capture) - ) - return marked(string) - App.i18n.translateContent(string) - - ContentTypeIcon: (contentType) -> - contentType = App.Utils.contentTypeCleanup(contentType) - icons = - # image - 'image/jpeg': 'file-image' - 'image/jpg': 'file-image' - 'image/png': 'file-image' - 'image/svg': 'file-image' - 'image/gif': 'file-image' - # documents - 'application/pdf': 'file-pdf' - 'application/msword': 'file-word' # .doc, .dot - 'application/vnd.ms-word': 'file-word' - 'application/vnd.oasis.opendocument.text': 'file-word' - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'file-word' # .docx - 'application/vnd.openxmlformats-officedocument.wordprocessingml.template': 'file-word' # .dotx - 'application/vnd.ms-excel': 'file-excel' # .xls - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'file-excel' # .xlsx - 'application/vnd.oasis.opendocument.spreadsheet': 'file-excel' - 'application/vnd.ms-powerpoint': 'file-powerpoint' # .ppt - 'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'file-powerpoint' # .pptx - 'application/vnd.oasis.opendocument.presentation': 'file-powerpoint' - 'text/plain': 'file-text' - 'text/html': 'file-code' - 'application/json': 'file-code' - 'message/rfc822': 'file-email' - # code - 'application/json': 'file-code' - # text - 'text/plain': 'file-text' - 'text/rtf': 'file-text' - # archives - 'application/gzip': 'file-archive' - 'application/zip': 'file-archive' - return icons[contentType] - - canDownload: (contentType) -> - contentType = App.Utils.contentTypeCleanup(contentType) - contentType != 'text/html' - - canPreview: (contentType) -> - return false if _.isEmpty(contentType) - return true if contentType.match(/image\/(png|jpg|jpeg|gif)/i) - false - @viewPrint: (object, attributeName, attributes, table) -> if !attributes attributes = {} @@ -342,7 +148,7 @@ class App extends Spine.Controller @view: (name) -> template = (params = {}) -> - JST["app/views/#{name}"](_.extend(params, helper)) + JST["app/views/#{name}"](_.extend(params, App.ViewHelpers)) template class App.UiElement diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee index f4efa7891..89b87584f 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.coffee @@ -952,6 +952,34 @@ class App.Utils path = if window.svgPolyfill then '' else 'assets/images/icons.svg' "" + @fontIcon: (name, font) -> + @loadIconFont(font) + "#{String.fromCharCode('0x'+ name)}" + + @loadIconFont: (font) -> + el = $("[data-icon-font=\"#{font}\"]") + return if el.length # already loaded + + el = $("