OSDN Git Service

3704d7ec0c4b8575f408543f1b3a1b04f39f82a8
[pettanr/pettanr.git] / app / assets / javascripts / pettanr.js.coffee
1 class Pettanr\r
2   class Pettanr.AppHelper\r
3     @manifest: () ->\r
4       Manifest.manifest\r
5     \r
6     @full_url: (filename) ->\r
7       request.protocol + request.host_with_port + filename\r
8     \r
9     @t_m: (label) ->\r
10       l = label.split('.')\r
11       if l.length > 2\r
12         label\r
13       else\r
14         if l.length == 1\r
15           I18n.t('activerecord.models.' + Pettanr[label].item_name())\r
16         else\r
17           I18n.t('activerecord.models.attribtes.' + Pettanr[l.first].item_name() + '.' + l.last)\r
18     \r
19     @t_select_items: (items) ->\r
20       _.map items, (i) ->\r
21         [t(i[0]), i[1]]\r
22     \r
23     @t_selected_item: (name, index) ->\r
24       I18n.t(Manifest.manifest().system_resources.select_items[name][index][0])\r
25     \r
26     @icon_tag: (name, opt = {}) ->\r
27       title = if opt['object']\r
28         name + ' ID:' + opt['object'].get(id).toString()\r
29       else\r
30         name\r
31       size = if opt['size']\r
32         parseInt(opt['size'])\r
33       else\r
34         35\r
35       "<img src=\"" + '/images/' + Pettanr.underscore(name) + '.gif' + "\" width=" + size.toString() + " height=" + size.toString() + " alt=\"" + name + ' Icon' + "title=\"" + title + ">"\r
36 \r
37   class Pettanr.AppController\r
38 \r
39   #>> https://gist.github.com/davidjbeveridge/3813724\r
40   @xeach: (arr, func, index=0) ->\r
41     if index < arr.length then [ func(arr[index], index), @xeach(arr, func, index + 1)... ] else []\r
42   \r
43   @camelize: (input) ->\r
44     pieces = input.split(/[\W_-]/)\r
45     @xeach(pieces, @capitalize).join("")\r
46   \r
47   @capitalize: (input) ->\r
48     input.charAt(0).toUpperCase() + input.slice(1)\r
49   \r
50   @lowercase: (input) ->\r
51     input.toLowerCase()\r
52    \r
53   @underscore: (input) ->\r
54     pieces = input.replace(/([A-Z])/g, '_$1').split(/[\W_-]/).filter (n) -> !!n\r
55     @xeach(pieces, @lowercase ).join("_")\r
56   # <<\r
57   @is_a_string: (str) ->\r
58     if (str instanceof String) or (typeof str == "string")\r
59       true\r
60     else\r
61       false\r
62   \r
63 @Pettanr = Pettanr\r