X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fassets%2Fjavascripts%2Fpettanr.js.coffee;h=544c2502cc2f90066cd2e5c14b3a1c518701dab6;hb=b16d4899d5e7332f572a40ba1ca32250a7952413;hp=eee96309a8ddc7e29c801983dcbe08f05861dc0d;hpb=b6289ebd47279820bd7238bf106ec5440b6832fe;p=pettanr%2Fpettanr.git diff --git a/app/assets/javascripts/pettanr.js.coffee b/app/assets/javascripts/pettanr.js.coffee index eee96309..544c2502 100644 --- a/app/assets/javascripts/pettanr.js.coffee +++ b/app/assets/javascripts/pettanr.js.coffee @@ -38,10 +38,44 @@ class Pettanr else '' + @truncate: (str, length = null) -> + s = Pettanr.to_s(str) + if length and s.length > 3 # 3 = '...' + r = s.substr(0, length - 4) + r = r.concat( '...') if s.length > length - 3 + r + else + Pettanr.to_s(str) + + @format_date: (date) -> + y = ('000' + (date.getFullYear())).slice(-4) + m = ('0' + (date.getMonth() + 1)).slice(-2) + d = ('0' + date.getDate()).slice(-2) + h = ('0' + date.getHours()).slice(-2) + n = ('0' + date.getMinutes()).slice(-2) + s = ('0' + date.getSeconds()).slice(-2) + y + '/' + m + '/' + d + ' ' + h + ':' + n + ':' + s + + @to_style: (hash) -> + a = _.map hash, (n, k) -> + Pettanr.to_s(k) + ': ' + Pettanr.to_s(n) + a.join('; ') + @url: (controller_name, action_name, params) -> - controller = Manifest.manifest().controllers[controller_name] - action = controller.actions[action_name] - action.url(params) + if controller = Manifest.manifest().controllers[controller_name] + # convert from manifest + action = controller.actions[action_name] + action.url(params) + else + # has no manifest + controller_name + '/' + action_name + + @params_to_url: (params) -> + return '' if params['controller'] == 'folders' and params['action'] == 'root' + @url(params['controller'], params['action'], params) + + @is_sns: () -> + Manifest.manifest().magic_numbers.run_mode != 0 class Pettanr.AppHelper @manifest: () -> @@ -58,7 +92,7 @@ class Pettanr if l.length == 1 I18n.t('activerecord.models.' + Pettanr[label].item_name()) else - Pettanr.AppHelper.t_a(Pettanr[l.first].item_name(), l.last) + Pettanr.AppHelper.t_a(Pettanr[l[0]].item_name(), l[1]) @t_a: (item_name, attr_name) -> I18n.t('activerecord.attributes.' + item_name + '.' + attr_name) @@ -71,133 +105,15 @@ class Pettanr I18n.t(Manifest.manifest().system_resources.select_items[name][index][0]) @distance_of_time_in_words_to_now: (datetime) -> - datetime - - class Pettanr.CounterModel extends Backbone.Model - initialize: (attr, options) -> - @url = options['url'] - - count: () -> - @get('count') - - class Pettanr.PageStatus - - constructor: (options) -> - @action = options['action'] - @params = options['params'] - @current_page = parseInt(@params['page']) || 1 - @per_page = @params['page_size'] || 25 - @window_size = 3 - @counter = new Pettanr.CounterModel({}, {url: '/' + @action.counter_url(@params)}) - - class Pettanr.FilerCollection extends Backbone.Collection + if Pettanr.is_blank(datetime) + '' + else + $.timeago(datetime) - initialize: (models, options) -> - @model = options['model'] - @action = options['action'] - @params = options['params'] - - @url = '/' + @action.url(@params) - class Pettanr.AppController - constructor: () -> - @params = {} - @operators = window.operators - - set_model: () -> - @my_controller = Manifest.manifest().controllers[@params['controller']] - @my_action = @my_controller.actions[@params['action']] - @my_model = Manifest.manifest().models[@my_action.item_name] - @my_model_class = @my_model.classify() - - set_list: () -> - @set_model() - @my_list_model = Manifest.manifest().models[@my_action.item_name] - @my_list_model_class = @my_list_model.classify() - @list_options = { - model: @my_list_model_class, - action: @my_action, - params: @params - } - @page_status = new Pettanr.PageStatus(@list_options) - @list = new Pettanr.FilerCollection({}, @list_options) - - set_show: () -> - @set_model() - @item = new @my_model_class({id: @params['id']}) - - filer_list: () -> - @set_list() - @pager = new Locmare.FilerModule.DefaultPager({page_status: @page_status}) - f = new Locmare.Filer({ - el: "#pettanr", - item_name: @my_list_model_class.item_name(), - collection: @list, - pager: @pager, - operators: @operators - }) - - show_prof: () -> - profiler = new Locmare.Profiler({ - el: "#pettanr", - item_name: @item.item_name(), - item: @item, - operators: @operators - }) - - set_new: () -> - @set_model() - @item = new @my_model_class({id: @params['id']}) - @item.boosts 'post' - @item.supply_default() - - set_edit: () -> - @set_model() - @item = new @my_model_class({id: @params['id']}) - _this = this - @item.fetch().done -> - _this.item.boosts 'post' - _this.render_form() - - render_form: () -> - @form = new Locmare.Form({ - form_name: @item.item_name(), - item: @item, - mounted: true, - submit: 'default', - operators: @operators, - action: '/' + @item.table_name() + '/' + Pettanr.to_s(@item.get('id')) - }) - $("#pettanr").html(@form.render().el) - - form_new: () -> - @set_new() - @render_form() - - form_edit: () -> - @set_edit() - - class Pettanr.FilerRender - constructor: (item_name, list_result, pager_type, operators) -> - @item_name = item_name - @list_result = list_result - @pager_type = pager_type - @operators = operators - _this = this - @list_result.fetch({}).done () -> - _this.render() - - render: () -> - items = @list_result.models - f = new Locmare.Filer({ - item_name: @item_name, - items: items, - list_result: @list_result, - pager_type: @pager_type, - operators: @operators - }) - $("#pettanr").html(f.render().el) - + @cache = null # set by main + @credits = {} + #>> https://gist.github.com/davidjbeveridge/3813724 @xeach: (arr, func, index=0) -> if index < arr.length then [ func(arr[index], index), @xeach(arr, func, index + 1)... ] else []