else\r
''\r
\r
+ @truncate: (str, length = null) ->\r
+ s = Pettanr.to_s(str)\r
+ if length and s.length > 3 # 3 = '...'\r
+ r = s.substr(0, length - 4)\r
+ r = r.concat( '...') if s.length > length - 3\r
+ r\r
+ else\r
+ Pettanr.to_s(str)\r
+ \r
+ @format_date: (date) ->\r
+ y = ('000' + (date.getFullYear())).slice(-4)\r
+ m = ('0' + (date.getMonth() + 1)).slice(-2)\r
+ d = ('0' + date.getDate()).slice(-2)\r
+ h = ('0' + date.getHours()).slice(-2)\r
+ n = ('0' + date.getMinutes()).slice(-2)\r
+ s = ('0' + date.getSeconds()).slice(-2)\r
+ y + '/' + m + '/' + d + ' ' + h + ':' + n + ':' + s\r
+ \r
+ @to_style: (hash) ->\r
+ a = _.map hash, (n, k) ->\r
+ Pettanr.to_s(k) + ': ' + Pettanr.to_s(n)\r
+ a.join('; ')\r
+ \r
@url: (controller_name, action_name, params) ->\r
- controller = Manifest.manifest().controllers[controller_name]\r
- action = controller.actions[action_name]\r
- action.url(params)\r
+ if controller = Manifest.manifest().controllers[controller_name]\r
+ # convert from manifest\r
+ action = controller.actions[action_name]\r
+ action.url(params)\r
+ else\r
+ # has no manifest\r
+ controller_name + '/' + action_name\r
+ \r
+ @params_to_url: (params) ->\r
+ return '' if params['controller'] == 'folders' and params['action'] == 'root'\r
+ @url(params['controller'], params['action'], params)\r
+ \r
+ @is_sns: () ->\r
+ Manifest.manifest().magic_numbers.run_mode != 0\r
\r
class Pettanr.AppHelper\r
@manifest: () ->\r
if l.length == 1\r
I18n.t('activerecord.models.' + Pettanr[label].item_name())\r
else\r
- Pettanr.AppHelper.t_a(Pettanr[l.first].item_name(), l.last)\r
+ Pettanr.AppHelper.t_a(Pettanr[l[0]].item_name(), l[1])\r
\r
@t_a: (item_name, attr_name) ->\r
I18n.t('activerecord.attributes.' + item_name + '.' + attr_name)\r
\r
@t_select_items: (items) ->\r
_.map items, (i) ->\r
- [t(i[0]), i[1]]\r
+ [I18n.t(i[0]), i[1]]\r
\r
@t_selected_item: (name, index) ->\r
I18n.t(Manifest.manifest().system_resources.select_items[name][index][0])\r
\r
@distance_of_time_in_words_to_now: (datetime) ->\r
- datetime\r
- \r
- class Pettanr.CounterModel extends Backbone.Model\r
- initialize: (attr, options) ->\r
- @url = options['url']\r
- \r
- count: () ->\r
- @get('count')\r
- \r
- class Pettanr.Pager extends Backbone.View\r
- \r
- initialize: (options) ->\r
- @action = options['action']\r
- @params = options['params']\r
- @current_page = @params['page']\r
- @per_page = @params['page_size']\r
- @window_size = 3\r
- @counter = new Pettanr.CounterModel({}, {url: '/' + @action.counter_url(@params)})\r
- _this = this\r
- @counter.fetch().done ->\r
- _this.total_page = (@total / _this.per_page) + 1\r
- \r
- class Pettanr.FilerCollection extends Backbone.Collection\r
+ if Pettanr.is_blank(datetime)\r
+ ''\r
+ else\r
+ $.timeago(datetime)\r
\r
- initialize: (models, options) ->\r
- @model = options['model']\r
- @action = options['action']\r
- @params = options['params']\r
- \r
- @url = '/' + @action.url(@params)\r
\r
- class Pettanr.AppController\r
- constructor: () ->\r
- @params = {}\r
- @operators = window.operators\r
- \r
- set_model: () ->\r
- @my_controller = Manifest.manifest().controllers[@params['controller']]\r
- @my_action = @my_controller.actions[@params['action']]\r
- @my_model = Manifest.manifest().models[@my_controller.item_name]\r
- @my_model_class = @my_model.classify()\r
- \r
- set_list: () ->\r
- @set_model()\r
- @my_list_model = Manifest.manifest().models[@my_action.item_name]\r
- @my_list_model_class = @my_list_model.classify()\r
- @pager = new Pettanr.Pager({action: @my_action, params: @params})\r
- @list = new Pettanr.FilerCollection({}, {model: @my_list_model_class, action: @my_action, params: @params})\r
- \r
- set_show: () ->\r
- @set_model()\r
- @item = new @my_model_class({id: @params['id']})\r
- \r
- filer_list: () ->\r
- @set_list()\r
- f = new Locmare.Filer({\r
- el: "#pettanr",\r
- item_name: @my_list_model_class.item_name(), \r
- collection: @list, \r
- pager: @pager, \r
- operators: @operators\r
- })\r
- \r
- show_prof: () ->\r
- profiler = new Locmare.Profiler({\r
- el: "#pettanr",\r
- item_name: @item.item_name(), \r
- item: @item, \r
- operators: @operators\r
- })\r
- \r
- class Pettanr.FilerRender\r
- constructor: (item_name, list_result, pager_type, operators) ->\r
- @item_name = item_name\r
- @list_result = list_result\r
- @pager_type = pager_type\r
- @operators = operators\r
- _this = this\r
- @list_result.fetch({}).done () ->\r
- _this.render()\r
- \r
- render: () ->\r
- items = @list_result.models\r
- f = new Locmare.Filer({\r
- item_name: @item_name, \r
- items: items, \r
- list_result: @list_result, \r
- pager_type: @pager_type, \r
- operators: @operators\r
- })\r
- $("#pettanr").html(f.render().el)\r
-\r
+ @cache = null # set by main\r
+ @credits = {}\r
+ \r
#>> https://gist.github.com/davidjbeveridge/3813724\r
@xeach: (arr, func, index=0) ->\r
if index < arr.length then [ func(arr[index], index), @xeach(arr, func, index + 1)... ] else []\r