2 # Foo.class -> Pettanr[@constructor.name]
\r
7 @is_a_string: (str) ->
\r
8 if (str instanceof String) or (typeof str == "string")
\r
13 @is_number: (str) ->
\r
14 if typeof(str) != 'number' && typeof(str) != 'string'
\r
17 n = if typeof(str) == 'string'
\r
24 if @is_a_string(str)
\r
29 class Pettanr.AppHelper
\r
33 @full_url: (filename) ->
\r
34 request.protocol + request.host_with_port + filename
\r
37 l = label.split('.')
\r
42 I18n.t('activerecord.models.' + Pettanr[label].item_name())
\r
44 Pettanr.AppHelper.t_a(Pettanr[l.first].item_name(), l.last)
\r
46 @t_a: (item_name, attr_name) ->
\r
47 I18n.t('activerecord.attributes.' + item_name + '.' + attr_name)
\r
49 @t_select_items: (items) ->
\r
53 @t_selected_item: (name, index) ->
\r
54 I18n.t(Manifest.manifest().system_resources.select_items[name][index][0])
\r
56 class Pettanr.AppHelperImg extends Backbone.View
\r
59 initialize: (options) ->
\r
61 @size = options.size
\r
64 this.$el.attr('src', @src)
\r
65 this.$el.attr('width', @size)
\r
66 this.$el.attr('height', @size)
\r
69 @image_tag: (src, opt = {}) ->
\r
70 size = if opt['size']
\r
71 parseInt(opt['size'])
\r
74 i = new Pettanr.AppHelperImg({src: src, size: size})
\r
75 i.render().el.outerHTML
\r
77 class Pettanr.AppHelperIcon extends Backbone.View
\r
80 initialize: (options) ->
\r
81 @name = options.name
\r
83 title = if @opt['object']
\r
84 name + ' ID:' + @opt['object'].get(id).toString()
\r
87 size = if @opt['size']
\r
88 parseInt(@opt['size'])
\r
93 this.$el.attr('src', '/images/' + Pettanr.underscore(@name) + '.gif')
\r
94 this.$el.attr('width', @size)
\r
95 this.$el.attr('height', @size)
\r
98 @icon_tag: (name, opt = {}) ->
\r
99 title = if opt['object']
\r
100 name + ' ID:' + opt['object'].get(id).toString()
\r
103 size = if opt['size']
\r
104 parseInt(opt['size'])
\r
107 "<img src=\"" + '/images/' + Pettanr.underscore(name) + '.gif' + "\" width=" + size.toString() + " height=" + size.toString() + " alt=\"" + name + ' Icon' + "title=\"" + title + ">"
\r
109 @distance_of_time_in_words_to_now: (datetime) ->
\r
112 class Pettanr.CounterModel extends Backbone.Model
\r
113 initialize: (attr, options) ->
\r
114 @url = options['url']
\r
116 class Pettanr.FilerCollection extends Backbone.Collection
\r
118 initialize: (models, options) ->
\r
119 params = options['params']
\r
120 i = if params['id']
\r
124 a = if params['action'] != 'index'
\r
129 @page = params['page']
\r
130 @page_size = params['page_size']
\r
132 q.push('page=' + Pettanr.to_s(@page)) if @page
\r
133 q.push('page_size=' + Pettanr.to_s(@page_size)) if @page_size
\r
134 qry = if q.length > 0
\r
138 @url = '/' + params['controller'] + '/' + i + a + qry
\r
139 @total = new Pettanr.CounterModel({}, {url: '/' + params['controller'] + '/' + i + 'count_' + a})
\r
140 @model = options['model']
\r
142 class Pettanr.AppController
\r
147 @my_controller = Manifest.manifest().controllers[@params['controller']]
\r
148 @my_action = @my_controller.actions[@params['action']]
\r
149 @my_model = Manifest.manifest().models[@my_controller.item_name]
\r
150 @my_model_class = @my_model.classify()
\r
154 @my_list_model = Manifest.manifest().models[@my_action.item_name]
\r
155 @my_list_model_class = @my_list_model.classify()
\r
156 @list = new Pettanr.FilerCollection({}, {model: @my_list_model_class, params: @params})
\r
160 f = new Locmare.Filer({
\r
162 item_name: @my_list_model_class.item_name(),
\r
164 list_result: @list,
\r
165 pager_type: 'default',
\r
166 operators: window.operators
\r
169 class Pettanr.FilerRender
\r
170 constructor: (item_name, list_result, pager_type, operators) ->
\r
171 @item_name = item_name
\r
172 @list_result = list_result
\r
173 @pager_type = pager_type
\r
174 @operators = operators
\r
176 @list_result.fetch({}).done () ->
\r
180 items = @list_result.models
\r
181 f = new Locmare.Filer({
\r
182 item_name: @item_name,
\r
184 list_result: @list_result,
\r
185 pager_type: @pager_type,
\r
186 operators: @operators
\r
188 $("#pettanr").html(f.render().el)
\r
190 #>> https://gist.github.com/davidjbeveridge/3813724
\r
191 @xeach: (arr, func, index=0) ->
\r
192 if index < arr.length then [ func(arr[index], index), @xeach(arr, func, index + 1)... ] else []
\r
194 @camelize: (input) ->
\r
195 pieces = input.split(/[\W_-]/)
\r
196 @xeach(pieces, @capitalize).join("")
\r
198 @capitalize: (input) ->
\r
199 input.charAt(0).toUpperCase() + input.slice(1)
\r
201 @lowercase: (input) ->
\r
202 input.toLowerCase()
\r
204 @underscore: (input) ->
\r
205 pieces = input.replace(/([A-Z])/g, '_$1').split(/[\W_-]/).filter (n) -> !!n
\r
206 @xeach(pieces, @lowercase ).join("_")
\r