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
32 class Pettanr.AppHelper
\r
36 @full_url: (filename) ->
\r
37 request.protocol + request.host_with_port + filename
\r
40 l = label.split('.')
\r
45 I18n.t('activerecord.models.' + Pettanr[label].item_name())
\r
47 Pettanr.AppHelper.t_a(Pettanr[l.first].item_name(), l.last)
\r
49 @t_a: (item_name, attr_name) ->
\r
50 I18n.t('activerecord.attributes.' + item_name + '.' + attr_name)
\r
52 @t_select_items: (items) ->
\r
56 @t_selected_item: (name, index) ->
\r
57 I18n.t(Manifest.manifest().system_resources.select_items[name][index][0])
\r
59 class Pettanr.AppHelperA extends Backbone.View
\r
62 initialize: (options) ->
\r
63 @href = options.href
\r
64 @content = options.content
\r
67 this.$el.attr('href', @href)
\r
68 this.$el.html(@content)
\r
72 class Pettanr.AppHelperImg extends Backbone.View
\r
75 initialize: (options) ->
\r
77 @size = options.size
\r
78 @class_name = options.class_name
\r
81 this.$el.attr('src', @src)
\r
82 this.$el.attr('width', @size)
\r
83 this.$el.attr('height', @size)
\r
84 @el.className = @class_name
\r
87 @image_tag: (src, opt = {}) ->
\r
88 size = if opt['size']
\r
89 parseInt(opt['size'])
\r
92 i = new Pettanr.AppHelperImg({src: src, size: size})
\r
93 i.render().el.outerHTML
\r
95 class Pettanr.AppHelperIcon extends Backbone.View
\r
98 initialize: (options) ->
\r
99 @name = options.name
\r
101 title = if @opt['object']
\r
102 name + ' ID:' + @opt['object'].get(id).toString()
\r
105 size = if @opt['size']
\r
106 parseInt(@opt['size'])
\r
111 this.$el.attr('src', '/images/' + Pettanr.underscore(@name) + '.gif')
\r
112 this.$el.attr('width', @size)
\r
113 this.$el.attr('height', @size)
\r
116 @icon_tag: (name, opt = {}) ->
\r
117 title = if opt['object']
\r
118 name + ' ID:' + opt['object'].get(id).toString()
\r
121 size = if opt['size']
\r
122 parseInt(opt['size'])
\r
125 "<img src=\"" + '/images/' + Pettanr.underscore(name) + '.gif' + "\" width=" + size.toString() + " height=" + size.toString() + " alt=\"" + name + ' Icon' + "title=\"" + title + ">"
\r
127 @distance_of_time_in_words_to_now: (datetime) ->
\r
130 class Pettanr.CounterModel extends Backbone.Model
\r
131 initialize: (attr, options) ->
\r
132 @url = options['url']
\r
137 class Pettanr.PageStatus
\r
139 constructor: (options) ->
\r
140 @action = options['action']
\r
141 @params = options['params']
\r
142 @current_page = @params['page'] || 1
\r
143 @per_page = @params['page_size'] || 25
\r
145 @counter = new Pettanr.CounterModel({}, {url: '/' + @action.counter_url(@params)})
\r
147 class Pettanr.FilerCollection extends Backbone.Collection
\r
149 initialize: (models, options) ->
\r
150 @model = options['model']
\r
151 @action = options['action']
\r
152 @params = options['params']
\r
154 @url = '/' + @action.url(@params)
\r
156 class Pettanr.AppController
\r
159 @operators = window.operators
\r
162 @my_controller = Manifest.manifest().controllers[@params['controller']]
\r
163 @my_action = @my_controller.actions[@params['action']]
\r
164 @my_model = Manifest.manifest().models[@my_controller.item_name]
\r
165 @my_model_class = @my_model.classify()
\r
169 @my_list_model = Manifest.manifest().models[@my_action.item_name]
\r
170 @my_list_model_class = @my_list_model.classify()
\r
172 model: @my_list_model_class,
\r
173 action: @my_action,
\r
176 @page_status = new Pettanr.PageStatus(@list_options)
\r
177 @list = new Pettanr.FilerCollection({}, @list_options)
\r
181 @item = new @my_model_class({id: @params['id']})
\r
185 @pager = new Locmare.FilerModule.DefaultPager({page_status: @page_status})
\r
186 f = new Locmare.Filer({
\r
188 item_name: @my_list_model_class.item_name(),
\r
189 collection: @list,
\r
191 operators: @operators
\r
195 profiler = new Locmare.Profiler({
\r
197 item_name: @item.item_name(),
\r
199 operators: @operators
\r
202 class Pettanr.FilerRender
\r
203 constructor: (item_name, list_result, pager_type, operators) ->
\r
204 @item_name = item_name
\r
205 @list_result = list_result
\r
206 @pager_type = pager_type
\r
207 @operators = operators
\r
209 @list_result.fetch({}).done () ->
\r
213 items = @list_result.models
\r
214 f = new Locmare.Filer({
\r
215 item_name: @item_name,
\r
217 list_result: @list_result,
\r
218 pager_type: @pager_type,
\r
219 operators: @operators
\r
221 $("#pettanr").html(f.render().el)
\r
223 #>> https://gist.github.com/davidjbeveridge/3813724
\r
224 @xeach: (arr, func, index=0) ->
\r
225 if index < arr.length then [ func(arr[index], index), @xeach(arr, func, index + 1)... ] else []
\r
227 @camelize: (input) ->
\r
228 pieces = input.split(/[\W_-]/)
\r
229 @xeach(pieces, @capitalize).join("")
\r
231 @capitalize: (input) ->
\r
232 input.charAt(0).toUpperCase() + input.slice(1)
\r
234 @lowercase: (input) ->
\r
235 input.toLowerCase()
\r
237 @underscore: (input) ->
\r
238 pieces = input.replace(/([A-Z])/g, '_$1').split(/[\W_-]/).filter (n) -> !!n
\r
239 @xeach(pieces, @lowercase ).join("_")
\r