5 class Pettanr.AppHelper
\r
9 @full_url: (filename) ->
\r
10 request.protocol + request.host_with_port + filename
\r
13 l = label.split('.')
\r
18 I18n.t('activerecord.models.' + Pettanr[label].item_name())
\r
20 I18n.t('activerecord.models.attribtes.' + Pettanr[l.first].item_name() + '.' + l.last)
\r
22 @t_select_items: (items) ->
\r
26 @t_selected_item: (name, index) ->
\r
27 I18n.t(Manifest.manifest().system_resources.select_items[name][index][0])
\r
29 class Pettanr.AppHelperImg extends Backbone.View
\r
35 initialize: (options) ->
\r
37 @size = options.size
\r
40 this.$el.attr('src', @src)
\r
41 this.$el.attr('size', @size)
\r
44 @image_tag: (src, opt = {}) ->
\r
45 size = if opt['size']
\r
46 parseInt(opt['size'])
\r
49 i = new Pettanr.AppHelperImg({src: src, size: size})
\r
50 i.render().el.outerHTML
\r
52 @icon_tag: (name, opt = {}) ->
\r
53 title = if opt['object']
\r
54 name + ' ID:' + opt['object'].get(id).toString()
\r
57 size = if opt['size']
\r
58 parseInt(opt['size'])
\r
61 "<img src=\"" + '/images/' + Pettanr.underscore(name) + '.gif' + "\" width=" + size.toString() + " height=" + size.toString() + " alt=\"" + name + ' Icon' + "title=\"" + title + ">"
\r
63 @distance_of_time_in_words_to_now: (datetime) ->
\r
66 class Pettanr.AppController
\r
68 class Pettanr.FilerRender
\r
69 constructor: (item_name, list_result, pager_type, operators) ->
\r
70 @item_name = item_name
\r
71 @list_result = list_result
\r
72 @pager_type = pager_type
\r
73 @operators = operators
\r
75 @list_result.fetch({}).done () ->
\r
79 items = @list_result.models
\r
80 f = new Locmare.Filer({
\r
81 item_name: @item_name,
\r
83 list_result: @list_result,
\r
84 pager_type: @pager_type,
\r
85 operators: @operators
\r
87 $("#pettanr").html(f.render().el)
\r
89 #>> https://gist.github.com/davidjbeveridge/3813724
\r
90 @xeach: (arr, func, index=0) ->
\r
91 if index < arr.length then [ func(arr[index], index), @xeach(arr, func, index + 1)... ] else []
\r
93 @camelize: (input) ->
\r
94 pieces = input.split(/[\W_-]/)
\r
95 @xeach(pieces, @capitalize).join("")
\r
97 @capitalize: (input) ->
\r
98 input.charAt(0).toUpperCase() + input.slice(1)
\r
100 @lowercase: (input) ->
\r
101 input.toLowerCase()
\r
103 @underscore: (input) ->
\r
104 pieces = input.replace(/([A-Z])/g, '_$1').split(/[\W_-]/).filter (n) -> !!n
\r
105 @xeach(pieces, @lowercase ).join("_")
\r
107 @is_a_string: (str) ->
\r
108 if (str instanceof String) or (typeof str == "string")
\r