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
33 if @is_a_string(str)
\r
41 @url: (controller_name, action_name, params) ->
\r
42 controller = Manifest.manifest().controllers[controller_name]
\r
43 action = controller.actions[action_name]
\r
46 class Pettanr.AppHelper
\r
50 @full_url: (filename) ->
\r
51 request.protocol + request.host_with_port + filename
\r
54 l = label.split('.')
\r
59 I18n.t('activerecord.models.' + Pettanr[label].item_name())
\r
61 Pettanr.AppHelper.t_a(Pettanr[l.first].item_name(), l.last)
\r
63 @t_a: (item_name, attr_name) ->
\r
64 I18n.t('activerecord.attributes.' + item_name + '.' + attr_name)
\r
66 @t_select_items: (items) ->
\r
70 @t_selected_item: (name, index) ->
\r
71 I18n.t(Manifest.manifest().system_resources.select_items[name][index][0])
\r
73 @distance_of_time_in_words_to_now: (datetime) ->
\r
76 class Pettanr.CounterModel extends Backbone.Model
\r
77 initialize: (attr, options) ->
\r
78 @url = options['url']
\r
83 class Pettanr.PageStatus
\r
85 constructor: (options) ->
\r
86 @action = options['action']
\r
87 @params = options['params']
\r
88 @current_page = @params['page'] || 1
\r
89 @per_page = @params['page_size'] || 25
\r
91 @counter = new Pettanr.CounterModel({}, {url: '/' + @action.counter_url(@params)})
\r
93 class Pettanr.FilerCollection extends Backbone.Collection
\r
95 initialize: (models, options) ->
\r
96 @model = options['model']
\r
97 @action = options['action']
\r
98 @params = options['params']
\r
100 @url = '/' + @action.url(@params)
\r
102 class Pettanr.AppController
\r
105 @operators = window.operators
\r
108 @my_controller = Manifest.manifest().controllers[@params['controller']]
\r
109 @my_action = @my_controller.actions[@params['action']]
\r
110 @my_model = Manifest.manifest().models[@my_action.item_name]
\r
111 @my_model_class = @my_model.classify()
\r
115 @my_list_model = Manifest.manifest().models[@my_action.item_name]
\r
116 @my_list_model_class = @my_list_model.classify()
\r
118 model: @my_list_model_class,
\r
119 action: @my_action,
\r
122 @page_status = new Pettanr.PageStatus(@list_options)
\r
123 @list = new Pettanr.FilerCollection({}, @list_options)
\r
127 @item = new @my_model_class({id: @params['id']})
\r
131 @pager = new Locmare.FilerModule.DefaultPager({page_status: @page_status})
\r
132 f = new Locmare.Filer({
\r
134 item_name: @my_list_model_class.item_name(),
\r
135 collection: @list,
\r
137 operators: @operators
\r
141 profiler = new Locmare.Profiler({
\r
143 item_name: @item.item_name(),
\r
145 operators: @operators
\r
148 class Pettanr.FilerRender
\r
149 constructor: (item_name, list_result, pager_type, operators) ->
\r
150 @item_name = item_name
\r
151 @list_result = list_result
\r
152 @pager_type = pager_type
\r
153 @operators = operators
\r
155 @list_result.fetch({}).done () ->
\r
159 items = @list_result.models
\r
160 f = new Locmare.Filer({
\r
161 item_name: @item_name,
\r
163 list_result: @list_result,
\r
164 pager_type: @pager_type,
\r
165 operators: @operators
\r
167 $("#pettanr").html(f.render().el)
\r
169 #>> https://gist.github.com/davidjbeveridge/3813724
\r
170 @xeach: (arr, func, index=0) ->
\r
171 if index < arr.length then [ func(arr[index], index), @xeach(arr, func, index + 1)... ] else []
\r
173 @camelize: (input) ->
\r
174 pieces = input.split(/[\W_-]/)
\r
175 @xeach(pieces, @capitalize).join("")
\r
177 @capitalize: (input) ->
\r
178 input.charAt(0).toUpperCase() + input.slice(1)
\r
180 @lowercase: (input) ->
\r
181 input.toLowerCase()
\r
183 @underscore: (input) ->
\r
184 pieces = input.replace(/([A-Z])/g, '_$1').split(/[\W_-]/).filter (n) -> !!n
\r
185 @xeach(pieces, @lowercase ).join("_")
\r