class Pettanr @is_blank: (str) -> !str?.trim() @is_a_string: (str) -> if (str instanceof String) or (typeof str == "string") true else false @to_s: (str) -> if @is_a_string(str) str else '' class Pettanr.AppHelper @manifest: () -> Manifest.manifest @full_url: (filename) -> request.protocol + request.host_with_port + filename @t_m: (label) -> l = label.split('.') if l.length > 2 label else if l.length == 1 I18n.t('activerecord.models.' + Pettanr[label].item_name()) else I18n.t('activerecord.models.attribtes.' + Pettanr[l.first].item_name() + '.' + l.last) @t_select_items: (items) -> _.map items, (i) -> [t(i[0]), i[1]] @t_selected_item: (name, index) -> I18n.t(Manifest.manifest().system_resources.select_items[name][index][0]) class Pettanr.AppHelperImg extends Backbone.View tagName: 'img' initialize: (options) -> @src = options.src @size = options.size render: () -> this.$el.attr('src', @src) this.$el.attr('width', @size) this.$el.attr('height', @size) this @image_tag: (src, opt = {}) -> size = if opt['size'] parseInt(opt['size']) else 35 i = new Pettanr.AppHelperImg({src: src, size: size}) i.render().el.outerHTML class Pettanr.AppHelperIcon extends Backbone.View tagName: 'img' initialize: (options) -> @name = options.name @opt = options.opt title = if @opt['object'] name + ' ID:' + @opt['object'].get(id).toString() else name size = if @opt['size'] parseInt(@opt['size']) else 35 render: () -> this.$el.attr('src', '/images/' + Pettanr.underscore(@name) + '.gif') this.$el.attr('width', @size) this.$el.attr('height', @size) this @icon_tag: (name, opt = {}) -> title = if opt['object'] name + ' ID:' + opt['object'].get(id).toString() else name size = if opt['size'] parseInt(opt['size']) else 35 "\""" @distance_of_time_in_words_to_now: (datetime) -> datetime class Pettanr.AppController 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) #>> 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 [] @camelize: (input) -> pieces = input.split(/[\W_-]/) @xeach(pieces, @capitalize).join("") @capitalize: (input) -> input.charAt(0).toUpperCase() + input.slice(1) @lowercase: (input) -> input.toLowerCase() @underscore: (input) -> pieces = input.replace(/([A-Z])/g, '_$1').split(/[\W_-]/).filter (n) -> !!n @xeach(pieces, @lowercase ).join("_") # << @Pettanr = Pettanr