pinkman 0.9.9.8 → 0.9.9.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +12 -12
- data/app/assets/javascripts/pinkman_base/collection.coffee +48 -20
- data/app/assets/javascripts/pinkman_base/common.coffee +38 -9
- data/app/assets/javascripts/pinkman_base/controller.coffee +134 -36
- data/app/assets/javascripts/pinkman_base/mixins.coffee +8 -4
- data/app/assets/javascripts/pinkman_base/object.coffee.erb +15 -13
- data/app/assets/javascripts/pinkman_base/pinkman.coffee +16 -0
- data/app/assets/javascripts/pinkman_base/render.coffee.erb +17 -5
- data/app/assets/javascripts/pinkman_base/router.coffee +95 -46
- data/app/assets/javascripts/pinkman_base/tools.coffee +3 -3
- data/app/assets/stylesheets/_colors.scss +45 -0
- data/app/assets/stylesheets/_custom_colors.scss +7 -0
- data/app/assets/stylesheets/_mixins.scss +39 -0
- data/app/assets/stylesheets/_settings.scss +1 -0
- data/app/assets/stylesheets/pinkman/buttons.scss +15 -0
- data/app/assets/stylesheets/pinkman/colors.scss +99 -0
- data/app/assets/stylesheets/pinkman/containers.scss +15 -0
- data/app/assets/stylesheets/pinkman/elements.scss +33 -0
- data/app/assets/stylesheets/pinkman/forms.scss +89 -0
- data/app/assets/stylesheets/pinkman/grid.scss +120 -0
- data/app/assets/stylesheets/pinkman/imgs.scss +7 -0
- data/app/assets/stylesheets/pinkman/lists.scss +58 -0
- data/app/assets/stylesheets/pinkman/loaders.scss +495 -0
- data/app/assets/stylesheets/pinkman/margins.scss +65 -0
- data/app/assets/stylesheets/pinkman/portfolio.scss +59 -0
- data/app/assets/stylesheets/pinkman/pygments.css.erb +1 -0
- data/app/assets/stylesheets/pinkman/reset.scss +51 -0
- data/app/assets/stylesheets/pinkman/sector.scss +10 -0
- data/app/assets/stylesheets/pinkman/tables.scss +62 -0
- data/app/assets/stylesheets/pinkman/typo.scss +104 -0
- data/app/assets/stylesheets/pinkman.css +17 -0
- data/app/controllers/pinkman/pinkman_controller.rb +6 -0
- data/app/helpers/pinkman/pinkman_helper.rb +14 -0
- data/app/views/pinkman/_error_for.html.slim +4 -0
- data/app/views/pinkman/pinkman/_form_input.html.slim +4 -0
- data/app/views/pinkman/pinkman/_form_select.html.slim +13 -0
- data/app/views/pinkman/pinkman/_form_textarea.html.slim +4 -0
- data/app/views/pinkman/pinkman/hello.html.erb +53 -0
- data/config/routes.rb +7 -0
- data/lib/generators/pinkman/USAGE +60 -14
- data/lib/generators/pinkman/app_base_generator.rb +16 -4
- data/lib/generators/pinkman/controller_generator.rb +29 -0
- data/lib/generators/pinkman/crud_generator.rb +24 -0
- data/lib/generators/pinkman/initializer_generator.rb +12 -0
- data/lib/generators/pinkman/install_generator.rb +29 -2
- data/lib/generators/pinkman/model_generator.rb +2 -2
- data/lib/generators/pinkman/page_generator.rb +15 -0
- data/lib/generators/pinkman/route_generator.rb +40 -0
- data/lib/generators/pinkman/route_resource_generator.rb +40 -0
- data/lib/generators/pinkman/template_generator.rb +47 -0
- data/lib/generators/pinkman/templates/api.rb.erb +6 -6
- data/lib/generators/pinkman/templates/api_controller.rb +22 -18
- data/lib/generators/pinkman/templates/app.coffee.erb +1 -0
- data/lib/generators/pinkman/templates/app_app.coffee.erb +1 -0
- data/lib/generators/pinkman/templates/app_collection.coffee.erb +1 -1
- data/lib/generators/pinkman/templates/app_object.coffee.erb +1 -1
- data/lib/generators/pinkman/templates/app_router.coffee.erb +1 -0
- data/lib/generators/pinkman/templates/app_routes.coffee.erb +34 -0
- data/lib/generators/pinkman/templates/controller.coffee.erb +4 -0
- data/lib/generators/pinkman/templates/example.mixin.coffee.erb +32 -0
- data/lib/generators/pinkman/templates/hello.controller.coffee.erb +98 -0
- data/lib/generators/pinkman/templates/initializer.rb.erb +6 -0
- data/lib/generators/pinkman/templates/my.pinkman.app.js +70 -0
- data/lib/generators/pinkman/templates/pink_template.html.erb.erb +4 -0
- data/lib/generators/pinkman/templates/pink_template.html.haml.erb +3 -0
- data/lib/generators/pinkman/templates/pink_template.html.slim.erb +3 -0
- data/lib/generators/pinkman/templates/serializer.rb.erb +6 -6
- data/lib/pinkman/base_helper.rb +15 -0
- data/lib/pinkman/form_helper/form_helpers.rb +65 -0
- data/lib/pinkman/form_helper.rb +36 -0
- data/lib/pinkman/serializer/base.rb +0 -1
- data/lib/pinkman/version.rb +1 -1
- data/lib/pinkman/views_helpers/collection_helper.rb +16 -0
- data/lib/pinkman/views_helpers/conditional_helper.rb +19 -0
- data/lib/pinkman/views_helpers/dispatcher.rb +27 -0
- data/lib/pinkman/views_helpers/form_helper.rb +63 -0
- data/lib/pinkman/views_helpers/template_helper.rb +65 -0
- data/lib/pinkman/views_helpers/writer_helper.rb +31 -0
- data/lib/pinkman/views_helpers.rb +71 -0
- data/lib/pinkman.rb +31 -5
- data/public/jquery.pinkman.min.js +4 -0
- data/public/pinkman.min.js +2 -29
- metadata +61 -4
- data/app/helpers/pinkman_helper.rb +0 -87
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e07ead0e5cc58bc710c373c978561d76526e652119a348a593b7b38ca6b5da18
|
4
|
+
data.tar.gz: 76158be83a618863576e6daf9a0048c2d9ec4e7d58310cb1d3a761e89f860e6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2db85458e813b66546265bcf95f17bd80311c1af7fffdd36416f5a1c51f254779495ac217057ede54989cfb0abd55d764e7a386aa46b044cd02e67c54e713c33
|
7
|
+
data.tar.gz: 11a82138515a4e61a81d2f340020f19dc7e12340388d80c0daab9c0822af7244f886e67b494f9262bf1cc6b0bd1116bac61bb4f70fff0703ac22d0c37f03bcd6
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Pinkman
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Rails js framework.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -20,15 +18,17 @@ Or install it yourself as:
|
|
20
18
|
|
21
19
|
$ gem install pinkman
|
22
20
|
|
23
|
-
##
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
21
|
+
## TODO
|
22
|
+
|
23
|
+
- Controller Generator
|
24
|
+
- Template generator
|
25
|
+
- Partial generator
|
26
|
+
- rails g pinkman:install (install generator)
|
27
|
+
- pinkman config file (initializer)
|
28
|
+
- Organize javascript/pinkman folders and subfolders (app (folder (appobject appcol app app routes)), models, controllers)
|
29
|
+
- docs: Main Feature
|
30
|
+
- docs: Usage
|
31
|
+
- docs: doc everything
|
32
32
|
|
33
33
|
## Contributing
|
34
34
|
|
@@ -5,17 +5,12 @@ class window.PinkmanCollection extends window.PinkmanCommon
|
|
5
5
|
config:
|
6
6
|
memberClass: PinkmanObject
|
7
7
|
|
8
|
-
constructor: () ->
|
9
|
-
|
10
|
-
@isPink = true
|
8
|
+
constructor: (args...) ->
|
9
|
+
super(args...)
|
11
10
|
@isCollection = true
|
12
11
|
@pinkmanType = 'collection'
|
13
|
-
|
14
12
|
@collection = []
|
15
|
-
@pinkey = Pinkman.all.length
|
16
|
-
|
17
13
|
Pinkman.collections.push(this)
|
18
|
-
Pinkman.all.push(this)
|
19
14
|
|
20
15
|
# Desc: return an array of all members
|
21
16
|
# this behaviour makes life easier... trust me
|
@@ -33,15 +28,30 @@ class window.PinkmanCollection extends window.PinkmanCommon
|
|
33
28
|
# Desc: sum a certain attribute of every element
|
34
29
|
sum: (attr,callback) ->
|
35
30
|
if attr?
|
36
|
-
v = 0
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
31
|
+
v = if @any() then '___initial___' else 0
|
32
|
+
if $p.isString(attr)
|
33
|
+
@each (obj) ->
|
34
|
+
if Pinkman.isNumber(obj[attr])
|
35
|
+
v = 0 if v=='___initial___'
|
36
|
+
v = Number(obj[attr]) + v
|
37
|
+
else
|
38
|
+
v = '' if v=='___initial___'
|
39
|
+
v = obj[attr] + v
|
40
|
+
, =>
|
41
|
+
callback(this, v) if typeof callback == 'function'
|
42
|
+
return(v)
|
43
|
+
else if $p.isFunction(attr)
|
44
|
+
@each (obj) ->
|
45
|
+
current = attr(obj)
|
46
|
+
if $p.isNumber(current)
|
47
|
+
v = 0 if v=='___initial___'
|
48
|
+
v = Number(current) + v
|
49
|
+
else
|
50
|
+
v = '' if v=='___initial___'
|
51
|
+
v = current + v
|
52
|
+
, =>
|
53
|
+
callback(this, v) if typeof callback == 'function'
|
54
|
+
return(v)
|
45
55
|
else
|
46
56
|
callback(this,0) if typeof callback == 'function'
|
47
57
|
return(0)
|
@@ -97,7 +107,26 @@ class window.PinkmanCollection extends window.PinkmanCommon
|
|
97
107
|
selection.push(object)
|
98
108
|
callback(selection) if typeof callback == 'function'
|
99
109
|
return(selection)
|
100
|
-
|
110
|
+
|
111
|
+
# extract(attr):
|
112
|
+
# Desc: returns an array containing the value of "attr" from each member of this collection.
|
113
|
+
extract: (attr) ->
|
114
|
+
array = []
|
115
|
+
@each (o) ->
|
116
|
+
array.push(o[attr])
|
117
|
+
array
|
118
|
+
|
119
|
+
# groupBy(attr,callback)
|
120
|
+
# Desc: group collections by attr value
|
121
|
+
groupBy: (attr,callback) ->
|
122
|
+
obj = new Object
|
123
|
+
@each (record) =>
|
124
|
+
obj[record[attr]] = new @constructor unless obj[record[attr]]?
|
125
|
+
obj[record[attr]].push record
|
126
|
+
, ->
|
127
|
+
callback(obj) if $p.isFunction(callback)
|
128
|
+
return(obj)
|
129
|
+
|
101
130
|
# every element of this collection will be substituted by the element of the collection passed
|
102
131
|
absorb: (collection, callback) ->
|
103
132
|
if typeof collection == 'object' and collection.isPink and collection.isCollection
|
@@ -432,7 +461,7 @@ class window.PinkmanCollection extends window.PinkmanCommon
|
|
432
461
|
for obj in @collection
|
433
462
|
if obj[attribute] == query
|
434
463
|
filter.push obj
|
435
|
-
else if obj[attribute]? and (typeof obj[attribute] == "string") and (obj[attribute]!="") and (typeof query == "string") and (query!="") and (obj[
|
464
|
+
else if obj[attribute]? and (typeof obj[attribute] == "string") and (obj[attribute]!="") and (typeof query == "string") and (query!="") and (obj[attribute].toLowerCase().indexOf(query.toLowerCase()) > -1)
|
436
465
|
filter.push obj
|
437
466
|
callback(filter) if callback? and typeof callback == 'function'
|
438
467
|
return filter
|
@@ -466,14 +495,13 @@ class window.PinkmanCollection extends window.PinkmanCommon
|
|
466
495
|
# request: get /api/API_URL/
|
467
496
|
fetchFromUrl: (options) ->
|
468
497
|
if options? and typeof options == 'object' and options.url?
|
469
|
-
|
470
498
|
if Pinkman.hasScope(this)
|
471
499
|
options.params = new Object unless options.params?
|
472
500
|
options.params.scope = Pinkman.scope(this)
|
473
501
|
|
474
502
|
@doneFetching = null
|
475
503
|
@fetchingFrom = options.url
|
476
|
-
|
504
|
+
|
477
505
|
Pinkman.ajax.get
|
478
506
|
url: Pinkman.json2url(options.url,options.params)
|
479
507
|
complete: (response) =>
|
@@ -4,13 +4,20 @@ class window.PinkmanCommon
|
|
4
4
|
|
5
5
|
constructor: (attributesObject) ->
|
6
6
|
@_listening = true
|
7
|
+
@isPink = true
|
8
|
+
@pinkey = Pinkman.all.length
|
9
|
+
Pinkman.all.push(this)
|
7
10
|
@initialize(attributesObject) if attributesObject?
|
8
11
|
|
9
12
|
@mixin: (args...) ->
|
10
13
|
Pinkman.mixin(args...)
|
11
14
|
|
15
|
+
# DEPRECATED in favor of mix (bellow)
|
12
16
|
@mixit: (args...) ->
|
13
17
|
Pinkman.mixit(this,args...)
|
18
|
+
|
19
|
+
@mix: (args...) ->
|
20
|
+
Pinkman.mix(this,args...)
|
14
21
|
|
15
22
|
@isInstance: (object) ->
|
16
23
|
object.constructor is this
|
@@ -21,12 +28,14 @@ class window.PinkmanCommon
|
|
21
28
|
@set(key,value) if PinkmanObject.privateAttributes.indexOf(key) is -1
|
22
29
|
|
23
30
|
# Desc: return api url path
|
24
|
-
api: () ->
|
31
|
+
api: (paths...) ->
|
25
32
|
if @config? and @config.api?
|
26
33
|
if @config.api.charAt(0) == '/'
|
27
|
-
@config.api + '/'
|
34
|
+
url = @config.api + '/'
|
28
35
|
else
|
29
|
-
'/' + @config.api + '/'
|
36
|
+
url = '/' + @config.api + '/'
|
37
|
+
url = url + paths.join('/') if paths.length
|
38
|
+
return(url)
|
30
39
|
|
31
40
|
isInstanceOf: (prot) ->
|
32
41
|
this.constructor is prot
|
@@ -50,7 +59,7 @@ class window.PinkmanCommon
|
|
50
59
|
if @pinkey? and @_listening
|
51
60
|
sId = "__pSync__#{@pinkey}__"
|
52
61
|
clearTimeout(window[sId]) if window[sId]?
|
53
|
-
window[sId] = sleep 0.005, =>
|
62
|
+
window[sId] = $p.sleep 0.005, =>
|
54
63
|
# console.log "syncing #{@pinkey}"
|
55
64
|
@sync(attr) if @_listening
|
56
65
|
return this
|
@@ -68,35 +77,49 @@ class window.PinkmanCommon
|
|
68
77
|
true
|
69
78
|
|
70
79
|
lazySync: (args...)->
|
71
|
-
sleep 0.25, =>
|
80
|
+
$p.sleep 0.25, =>
|
72
81
|
@sync(args...)
|
73
82
|
|
74
83
|
stop: ->
|
84
|
+
console.log '[deprecated] stop function deprecated. Use unwatch instead.'
|
75
85
|
@_listening = no
|
76
|
-
|
86
|
+
|
87
|
+
watch: ->
|
88
|
+
@_listening = yes
|
89
|
+
|
90
|
+
unwatch: ->
|
91
|
+
@_listening = no
|
92
|
+
|
77
93
|
# Desc: sets the attribute as undefined (destroy attribute)
|
78
94
|
unset: (attr,callback) ->
|
79
95
|
delete this[attr]
|
80
96
|
callback(this) if typeof callback == 'function'
|
97
|
+
this
|
81
98
|
|
82
99
|
# --- Render related --- #
|
83
100
|
|
101
|
+
# Desc: log attr value in the console
|
102
|
+
log: (attr) ->
|
103
|
+
console.log this[attr]
|
104
|
+
|
84
105
|
render: (options) ->
|
85
106
|
if typeof options == 'object'
|
86
107
|
options.object = this
|
87
|
-
options.template = options.target + '-template' unless options.template? and options.template != ''
|
88
108
|
Pinkman.render options
|
89
109
|
else if typeof options == 'string'
|
90
110
|
opts = {object: this, target: options, template: options + '-template'}
|
91
111
|
Pinkman.render opts
|
92
|
-
else
|
112
|
+
else
|
93
113
|
@reRender()
|
94
114
|
|
95
115
|
reRender: (callback='') ->
|
96
116
|
Pinkman.reRender(this)
|
97
117
|
callback(this) if typeof callback == 'function'
|
98
118
|
return this
|
99
|
-
|
119
|
+
|
120
|
+
renderFirst: () ->
|
121
|
+
Pinkman.render @renderQueue.first()
|
122
|
+
|
100
123
|
renderLast: () ->
|
101
124
|
Pinkman.render @renderQueue.last()
|
102
125
|
|
@@ -128,6 +151,12 @@ class window.PinkmanCommon
|
|
128
151
|
@renderQueue = new PinkmanCollection unless @renderQueue?
|
129
152
|
@renderQueue.directPush(options)
|
130
153
|
|
154
|
+
hasError: ->
|
155
|
+
@errors?
|
156
|
+
|
157
|
+
hasErrors: ->
|
158
|
+
@hasError()
|
159
|
+
|
131
160
|
hasErrorOn: (attr) ->
|
132
161
|
if attr? and (Pinkman.isArray(attr) or Pinkman.isString(attr))
|
133
162
|
array = if Pinkman.isArray(attr) then attr else [attr]
|
@@ -20,7 +20,9 @@ class window.PinkmanController extends window.PinkmanObject
|
|
20
20
|
clear: ->
|
21
21
|
@actions.each (a) ->
|
22
22
|
a.clear()
|
23
|
-
|
23
|
+
|
24
|
+
render: (args...) ->
|
25
|
+
Pinkman.render(args...)
|
24
26
|
|
25
27
|
constructor: (args...) ->
|
26
28
|
@actions = new PinkmanActions
|
@@ -44,43 +46,99 @@ class window.PinkmanController extends window.PinkmanObject
|
|
44
46
|
|
45
47
|
# build a controller from user definition
|
46
48
|
# main: boolean argument that forces main function be executed
|
47
|
-
build: (main) ->
|
49
|
+
build: (main,routeMatcher) ->
|
48
50
|
if @builder? and typeof @builder == 'function'
|
49
51
|
@builder(this)
|
50
|
-
|
52
|
+
if @_layout and @isSummoned(main)
|
53
|
+
@_layout = @_layout + '-layout' unless /-layout$/.test(@_layout)
|
54
|
+
$p.render
|
55
|
+
template: @_layout
|
56
|
+
callback: (obj,content) ->
|
57
|
+
$('body').html(content)
|
58
|
+
routeMatcher.makeYielder() if routeMatcher?
|
59
|
+
else
|
60
|
+
routeMatcher.makeYielder() if routeMatcher?
|
61
|
+
@main() if @isSummoned(main)
|
51
62
|
return(true)
|
52
63
|
else
|
53
64
|
return(false)
|
54
|
-
|
65
|
+
|
66
|
+
isSummoned: (main) ->
|
67
|
+
@main? and (main or ($("##{@id}").length and typeof @main == 'function'))
|
68
|
+
|
69
|
+
layout: (layoutName) ->
|
70
|
+
@_layout = layoutName
|
71
|
+
|
55
72
|
action: (args...) ->
|
56
73
|
if args.length == 1
|
57
74
|
@actions.getBy('name',args[0])
|
58
75
|
else
|
59
76
|
[name, eventName,callback,unknown...] = args
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
# else
|
68
|
-
# console.log @pinkey
|
69
|
-
# console.log a.pinkey
|
70
|
-
# console.log "#{id}: nao listen"
|
71
|
-
return(a)
|
72
|
-
|
77
|
+
PinkmanAction.define
|
78
|
+
id: "#{@pinkey}-#{name}-#{eventName}"
|
79
|
+
name: name
|
80
|
+
eventName: eventName
|
81
|
+
callback: callback
|
82
|
+
controller: this
|
83
|
+
selector: "##{this.id} [data-action='#{name}']"
|
73
84
|
|
85
|
+
|
86
|
+
# verificar - verify
|
87
|
+
# mudei recentemente, pode estar cagado
|
74
88
|
esc: (callback) ->
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
89
|
+
PinkmanAction.define
|
90
|
+
id: 'esc'
|
91
|
+
eventName: 'keyup'
|
92
|
+
controller: this
|
93
|
+
selector: "##{this.id}"
|
94
|
+
callback: (obj, j, ev) ->
|
95
|
+
callback() if ev.keyCode == 27
|
83
96
|
|
97
|
+
|
98
|
+
# bindAll works by attaching a 'change' event handler to all [data-action] inside a form.
|
99
|
+
# but... in a few ocasions, the developer must have the capability to exclude certain attributes from this binding.
|
100
|
+
# thats when the "except" option comes in
|
101
|
+
# maybe a "only" option is going to be implemented in the near future
|
102
|
+
bindAllSelector: (id,options) ->
|
103
|
+
except = options.except if $p.isObject(options) and options.except?
|
104
|
+
selector = "##{@id} form [data-action], ##{@id} .form [data-action]"
|
105
|
+
|
106
|
+
# except handler
|
107
|
+
if except
|
108
|
+
throw 'Pinkman bindAll: except option should be a string or an array' if not $p.isString(except) and not $p.isArray(except)
|
109
|
+
except = [except] if $p.isString(except)
|
110
|
+
exceptionsArray = []
|
111
|
+
for excep in except
|
112
|
+
exceptionsArray.push "[data-action='#{excep}']"
|
113
|
+
selector = selector.replace(/\[data-action\]/g,"[data-action]:not(#{exceptionsArray.join(',')})")
|
114
|
+
|
115
|
+
# debugger
|
116
|
+
# console.log selector
|
117
|
+
|
118
|
+
# return selector
|
119
|
+
selector
|
120
|
+
|
121
|
+
|
122
|
+
bindAll: (args...) ->
|
123
|
+
if args.length == 1
|
124
|
+
if $p.isFunction(args[0])
|
125
|
+
callback = args[0]
|
126
|
+
else if $p.isObject(args[0])
|
127
|
+
options = args[0]
|
128
|
+
else if args.length == 2
|
129
|
+
callback = args.pop()
|
130
|
+
options = args.shift()
|
131
|
+
|
132
|
+
PinkmanAction.define
|
133
|
+
id: "#{@pinkey}-bindAll"
|
134
|
+
selector: @bindAllSelector(@id,options)
|
135
|
+
eventName: ['change','keyup']
|
136
|
+
controller: this
|
137
|
+
callback: (obj,$j) ->
|
138
|
+
obj.set($j.attr('name'),$j.val()) if obj[$j.attr('name')] != $j.val()
|
139
|
+
callback(obj,$j,$j.attr('name')) if typeof callback == 'function'
|
140
|
+
|
141
|
+
|
84
142
|
bind: (attribute,callback='') ->
|
85
143
|
if Pinkman.isArray(attribute)
|
86
144
|
@bindIndividually(attr,callback) for attr in attribute
|
@@ -88,13 +146,19 @@ class window.PinkmanController extends window.PinkmanObject
|
|
88
146
|
@bindIndividually(attribute,callback)
|
89
147
|
|
90
148
|
bindIndividually: (attribute,callback='') ->
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
149
|
+
# modifiquei recentemente, verificar se houver atribuições duplas, etc
|
150
|
+
# if $("##{@id}").length
|
151
|
+
# console.log "bindou: #{attribute}, #{callback}"
|
152
|
+
|
153
|
+
@action attribute, ['keyup','change'], (obj,$j,args...) ->
|
154
|
+
# console.log obj[attribute]
|
155
|
+
# console.log $j.val()
|
156
|
+
if obj[attribute] != $j.val()
|
157
|
+
# console.log 'trocou de valor'
|
158
|
+
obj.set(attribute,$j.val())
|
159
|
+
callback(obj,$j,args...) if callback? and typeof callback == 'function'
|
160
|
+
# else
|
161
|
+
# console.log 'mesmo valor'
|
98
162
|
|
99
163
|
bottom: (callback) ->
|
100
164
|
if $("##{@id}").length
|
@@ -183,11 +247,44 @@ class window.PinkmanControllers extends window.PinkmanCollection
|
|
183
247
|
class window.PinkmanAction extends window.PinkmanObject
|
184
248
|
|
185
249
|
constructor: (args...) ->
|
250
|
+
@_event_listening = new Object
|
186
251
|
super(args...)
|
252
|
+
@call = ->
|
187
253
|
@events = []
|
254
|
+
|
255
|
+
# helper to define custom actions
|
256
|
+
@define: (options) ->
|
257
|
+
throw 'Pinkman - Define Action: argument must be a object' unless $p.isObject(options)
|
258
|
+
throw 'Pinkman - Define Action: missing id' unless $p.hasAttribute(options,'id')
|
259
|
+
throw 'Pinkman - Define Action: missing eventName' unless $p.hasAttribute(options,'eventName')
|
260
|
+
throw 'Pinkman - Define Action: missing controller' unless $p.hasAttribute(options,'controller')
|
261
|
+
throw 'Pinkman - Define Action: missing selector' unless $p.hasAttribute(options,'selector')
|
262
|
+
# throw 'Pinkman - Define Action: missing callback' unless $p.hasAttribute(options,'callback')
|
263
|
+
# throw 'Pinkman - Define Action: callback must be a function' unless $p.isFunction('callback')
|
264
|
+
options.controller = Pinkman.controller(options.controller) if $p.isString(options.controller)
|
265
|
+
if options.controller.actions.empty(id: options.id)
|
266
|
+
a = new PinkmanAction
|
267
|
+
a.set 'id', options.id
|
268
|
+
a.set('name', if options.name then options.name else options.id)
|
269
|
+
a.set 'controller', options.controller
|
270
|
+
a.set 'selector', options.selector
|
271
|
+
a.set 'eventName', options.eventName
|
272
|
+
# a.log 'eventName'
|
273
|
+
a.set 'call', options.callback if options.callback
|
274
|
+
Pinkman.actions.push(a)
|
275
|
+
a.controller.actions.push(a)
|
276
|
+
a.listen()
|
277
|
+
return(a)
|
278
|
+
else
|
279
|
+
# console.log options.controller
|
280
|
+
# console.log options.id
|
281
|
+
return(options.controller.actions.getBy('id',options.id))
|
282
|
+
|
188
283
|
|
284
|
+
|
189
285
|
# Desc: mirrors/redirects a action to another already defined
|
190
286
|
mirror: (controllerID,actionName) ->
|
287
|
+
# console.log this
|
191
288
|
# gets all actions named 'action' in all controllers with 'controller' id
|
192
289
|
actions = new PinkmanActions
|
193
290
|
Pinkman.controllers.select(id: controllerID).each (c) ->
|
@@ -207,13 +304,15 @@ class window.PinkmanAction extends window.PinkmanObject
|
|
207
304
|
|
208
305
|
# Desc: removes event
|
209
306
|
clear: ->
|
307
|
+
@_event_listening = new Object
|
210
308
|
for ev in @events
|
211
309
|
$('body').off ev, @selector
|
212
310
|
|
213
311
|
# Desc: attaches one single event
|
214
312
|
attach: (eventName) ->
|
215
|
-
if Pinkman.isString(eventName)
|
313
|
+
if Pinkman.isString(eventName) and not @_event_listening[eventName]
|
216
314
|
action = this
|
315
|
+
action._event_listening[eventName] = yes
|
217
316
|
@events.push(eventName)
|
218
317
|
$('body').on eventName, action.selector, (ev) ->
|
219
318
|
# debugger
|
@@ -266,11 +365,10 @@ Pinkman.controller = (args...) ->
|
|
266
365
|
Pinkman.actions = new PinkmanActions
|
267
366
|
|
268
367
|
$(document).ready ->
|
269
|
-
sleep 0.1, ->
|
368
|
+
$p.sleep 0.1, ->
|
270
369
|
array = []
|
271
370
|
Pinkman.actions.each (a) ->
|
272
371
|
array.push(a.selector) if (a.eventName == 'click') or (Pinkman.isArray(a.eventName) and a.eventName.indexOf('click') !=-1)
|
273
372
|
|
274
373
|
selector = array.join(', ')
|
275
|
-
Pinkman.css(selector, 'cursor', 'pointer !important')
|
276
|
-
|
374
|
+
Pinkman.css(selector, 'cursor', 'pointer !important')
|
@@ -4,9 +4,9 @@ window.Pinkman.mixin = (name,mix) ->
|
|
4
4
|
mixin = new Pinkman.object
|
5
5
|
mixin.set 'mix', mix
|
6
6
|
mixin.set 'name',name
|
7
|
-
Pinkman.mixins.
|
7
|
+
Pinkman.mixins.forcePush mixin
|
8
8
|
|
9
|
-
window.Pinkman.
|
9
|
+
window.Pinkman.mix = (c,name) ->
|
10
10
|
mixin = Pinkman.mixins.getBy('name',name)
|
11
11
|
if mixin?
|
12
12
|
for n, method of mixin.mix
|
@@ -15,6 +15,10 @@ window.Pinkman.mixit = (c,name) ->
|
|
15
15
|
return(true)
|
16
16
|
else
|
17
17
|
false
|
18
|
+
|
19
|
+
window.Pinkman.mixit = (args...) ->
|
20
|
+
console.log '[DEPRECATED]: Use mix instead of mixin.'
|
21
|
+
Pinkman.mix(args...)
|
18
22
|
|
19
23
|
|
20
24
|
# --- Mixins - Usage --- #
|
@@ -25,10 +29,10 @@ window.Pinkman.mixit = (c,name) ->
|
|
25
29
|
|
26
30
|
|
27
31
|
# class window.Foo
|
28
|
-
# Pinkman.
|
32
|
+
# Pinkman.mix this, 'shitty'
|
29
33
|
|
30
34
|
# class window.Bar extends Pinkman.object
|
31
|
-
# @
|
35
|
+
# @mix 'shitty'
|
32
36
|
|
33
37
|
# a = new Foo
|
34
38
|
# a.shit(abc) -> 'abc is shit'
|
@@ -4,15 +4,10 @@ class window.PinkmanObject extends window.PinkmanCommon
|
|
4
4
|
|
5
5
|
constructor: (args...) ->
|
6
6
|
super(args...)
|
7
|
-
@isPink = true
|
8
7
|
@isObject = true
|
9
8
|
@pinkmanType = 'object'
|
10
|
-
|
11
9
|
@collections = new PinkmanCollection
|
12
|
-
@pinkey = Pinkman.all.length
|
13
|
-
|
14
10
|
Pinkman.objects.push(this)
|
15
|
-
Pinkman.all.push(this)
|
16
11
|
|
17
12
|
# Desc: assign attributes from a pure javascript object
|
18
13
|
# Usage: a.assign( {attribute: value} )
|
@@ -63,6 +58,12 @@ class window.PinkmanObject extends window.PinkmanCommon
|
|
63
58
|
keys: () ->
|
64
59
|
@attributesKeys()
|
65
60
|
|
61
|
+
extract: (args...) ->
|
62
|
+
a = new Object
|
63
|
+
(a[k] = this[k]) for k in args
|
64
|
+
return(a)
|
65
|
+
|
66
|
+
|
66
67
|
toString: () ->
|
67
68
|
array = []
|
68
69
|
array.push("(#{@className()})")
|
@@ -123,7 +124,7 @@ class window.PinkmanObject extends window.PinkmanCommon
|
|
123
124
|
@find: (id, callback='') ->
|
124
125
|
obj = new this
|
125
126
|
params = new Object
|
126
|
-
params.scope = Pinkman.scope(
|
127
|
+
params.scope = Pinkman.scope(obj)
|
127
128
|
|
128
129
|
Pinkman.ajax.get
|
129
130
|
url: Pinkman.json2url(obj.api() + id,params)
|
@@ -142,9 +143,7 @@ class window.PinkmanObject extends window.PinkmanCommon
|
|
142
143
|
url: @api()
|
143
144
|
data: @_data()
|
144
145
|
complete: (response) =>
|
145
|
-
@
|
146
|
-
delete @errors unless response.errors?
|
147
|
-
callback(this) if callback? and typeof callback=='function'
|
146
|
+
@default_response_handling(response,callback)
|
148
147
|
return(this)
|
149
148
|
|
150
149
|
update: (callback='') ->
|
@@ -153,11 +152,14 @@ class window.PinkmanObject extends window.PinkmanCommon
|
|
153
152
|
url: @api() + @id
|
154
153
|
data: @_data()
|
155
154
|
complete: (response) =>
|
156
|
-
@
|
157
|
-
delete @errors unless response.errors?
|
158
|
-
callback(this) if callback? and typeof callback=='function'
|
155
|
+
@default_response_handling(response,callback)
|
159
156
|
return(this)
|
160
|
-
|
157
|
+
|
158
|
+
default_response_handling: (response,callback) ->
|
159
|
+
@assign(response)
|
160
|
+
@unset 'errors' unless response.errors?
|
161
|
+
callback(this) if callback? and typeof callback=='function'
|
162
|
+
|
161
163
|
reload: (callback) ->
|
162
164
|
params = new Object
|
163
165
|
params.scope = Pinkman.scope(this)
|
@@ -25,6 +25,20 @@ class window.Pinkman
|
|
25
25
|
|
26
26
|
@isPrintable: (value) ->
|
27
27
|
@isString(value) or @isNumber(value)
|
28
|
+
|
29
|
+
@isObject: (value) ->
|
30
|
+
typeof value == 'object'
|
31
|
+
|
32
|
+
@isFunction: (value) ->
|
33
|
+
typeof value == 'function'
|
34
|
+
|
35
|
+
@hasAttribute: (obj,attr) ->
|
36
|
+
obj? and attr? and @isObject(obj) and obj[attr]? and obj[attr]
|
37
|
+
|
38
|
+
@sleep = (s,callback) ->
|
39
|
+
ms = s*1000
|
40
|
+
window['_sleeping'] = setTimeout(callback,ms)
|
41
|
+
|
28
42
|
|
29
43
|
# --- tools and facilities
|
30
44
|
|
@@ -221,6 +235,8 @@ class window.Pinkman
|
|
221
235
|
upload: (options...) ->
|
222
236
|
@file(options...)
|
223
237
|
|
238
|
+
window.$p = Pinkman
|
239
|
+
|
224
240
|
Pinkman.ready ->
|
225
241
|
unless Pinkman.pathname?
|
226
242
|
Pinkman.pathname = window.location.pathname
|