pinkman 0.9.9.9.0 → 0.9.9.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e07ead0e5cc58bc710c373c978561d76526e652119a348a593b7b38ca6b5da18
4
- data.tar.gz: 76158be83a618863576e6daf9a0048c2d9ec4e7d58310cb1d3a761e89f860e6f
3
+ metadata.gz: a881ee79d0d66ed3ebc8f82b1b5d596ef5d373a5215a446bcf6e72166f81a8c0
4
+ data.tar.gz: b47389d23b0a46031a0404f12d0dfd94a43cd630d3d2c99af179e25d89d6a66e
5
5
  SHA512:
6
- metadata.gz: 2db85458e813b66546265bcf95f17bd80311c1af7fffdd36416f5a1c51f254779495ac217057ede54989cfb0abd55d764e7a386aa46b044cd02e67c54e713c33
7
- data.tar.gz: 11a82138515a4e61a81d2f340020f19dc7e12340388d80c0daab9c0822af7244f886e67b494f9262bf1cc6b0bd1116bac61bb4f70fff0703ac22d0c37f03bcd6
6
+ metadata.gz: 432dd76d2feaf437c60e2c636948442c429a2294d9794d2ce5bfcb89f6b5e614611104319a5ea0e40a87c1c2a64baaf2c98de182dc610834fff96a0fd5ab02ee
7
+ data.tar.gz: c6210ddc7fa530694879c6d9e50ef3eabad31f118393b8e1415d1029fdee8a592d40c6cf35c23ab93acb53e11d953854fc56c9cc901771040c9f3bdab819ceae
@@ -159,6 +159,112 @@ class window.PinkmanController extends window.PinkmanObject
159
159
  callback(obj,$j,args...) if callback? and typeof callback == 'function'
160
160
  # else
161
161
  # console.log 'mesmo valor'
162
+
163
+
164
+ # === Autocomplete ===
165
+
166
+ # -- Usage: autocomplete(input_name,options)
167
+
168
+ # -- Overview
169
+ # 1: User types something
170
+ # 2: Pinkman searchs through a collection and then renders the result
171
+ # 3: User selects a record
172
+ # 4: Pinkman sends the selected record to callback function
173
+
174
+ # -- Parameters & Options
175
+ # @autocomplete(attribute,options)
176
+ # options:
177
+ # with: [collection]
178
+ # pinkman collection responsible for filtering/searching the results
179
+
180
+ # method: [search|yourCustomMethod]
181
+ # Search is the default. Anythings that filters by a 'query'.
182
+ # You can define a yourCustomMethod inside the collection model like this:
183
+ # yourCustomMethod: (user_query, callback) ->
184
+ # -- perform a selection based on user_query
185
+ # callback(this) if $p.isFunction(callback)
186
+
187
+ # template: [template-id] (optional)
188
+ # Any template that has a 'select-attribute' action
189
+ # If you don't specify a template, Pinkman will try "attribute-autocomplete-template" by default
190
+
191
+ # target: [target-id]
192
+ # Where pinkman should yield results
193
+ # If you don't specify a target, Pinkman will try "attribute-autocomplete" by default
194
+
195
+ # loading: loading function
196
+ # Run something before searching (you can use it for some loading animation)
197
+
198
+ # call: callback function.
199
+ # What to do when user selects something?
200
+ autocomplete: (attr_name, options) ->
201
+ # error handling / verifing args
202
+ throw 'Pinkman Autocomplete: Missing options object' unless $p.isObject(options)
203
+ throw 'Pinkman Autocomplete: Missing "with" collection' unless options.with?
204
+ throw 'Pinkman Autocomplete: Missing "call" callback function' unless $p.isFunction(options.call)
205
+
206
+ # variables // user options // default options
207
+ collection = options.with
208
+ callback = options.call
209
+ template = if options.template? then options.template else "#{attr_name}-autocomplete"
210
+ target = if options.target? then options.target else "#{attr_name}-autocomplete"
211
+ method = if options.method? then options.method else 'search'
212
+ loading = options.loading if $p.isFunction(options.loading)
213
+ autoHide = if options.autoHide? then options.autoHide else yes
214
+ autoWidth = if options.autoWidth? then options.autoWidth else yes
215
+ wait = if options.wait? then options.wait else 0.75
216
+ waitTimerName = "#{attr_name}AutocompleteTimer"
217
+
218
+ # hide initially
219
+ $("##{target}").hide() if autoHide
220
+
221
+ # resize autocomplete
222
+ if autoWidth
223
+ $(window).resize ->
224
+ $("##{target}").width($("input[name='#{attr_name}']").innerWidth() - ($("##{target}").innerWidth() - $("##{target}").width()))
225
+
226
+ # responding to user typing
227
+ @bind attr_name, (obj,j) ->
228
+
229
+ # loading
230
+ loading(obj,j,attr_name) if loading?
231
+
232
+ # removes autocompleted Class
233
+ j.removeClass('autocompleted')
234
+
235
+ # wait until user finish typing
236
+ clearTimeout(window[waitTimerName]) if window[waitTimerName]?
237
+ window[waitTimerName] = $p.sleep wait, =>
238
+
239
+ # calls the filter method (search)
240
+ collection[method] obj[attr_name], (collection) ->
241
+
242
+ # render results
243
+ collection.render
244
+ template: template
245
+ target: target
246
+ callback: ->
247
+ # Hide or show autocomplete
248
+ if autoHide
249
+ if obj[attr_name]? and obj[attr_name] != ''
250
+ $("##{target}").fadeIn()
251
+ else
252
+ $("##{target}").fadeOut()
253
+
254
+ # Set the autocomplete target width to same as the input
255
+ if autoWidth
256
+ $("##{target}").width($("input[name='#{attr_name}']").innerWidth() - ($("##{target}").innerWidth() - $("##{target}").width()))
257
+
258
+ # user chooses something and click
259
+ @action "select-#{attr_name}", 'click', (args...) =>
260
+ # console.log "#{@selector()} input[action='#{attr_name}']"
261
+ $input = $("#{@selector()} input[data-action='#{attr_name}']")
262
+ $input.addClass('autocompleted')
263
+ obj = Pinkman.get($input.data('pinkey'))
264
+ $("##{target}").fadeOut() if autoHide
265
+ callback(obj,$input,args...)
266
+
267
+
162
268
 
163
269
  bottom: (callback) ->
164
270
  if $("##{@id}").length
@@ -172,7 +278,7 @@ class window.PinkmanController extends window.PinkmanObject
172
278
  Pinkman._lastEndOfPage = t
173
279
  callback()
174
280
  , 50
175
-
281
+
176
282
  endBottom: () ->
177
283
  Pinkman._bottomTriggered = false
178
284
 
@@ -190,7 +296,7 @@ class window.PinkmanController extends window.PinkmanObject
190
296
 
191
297
  scrolling: (callback) ->
192
298
  if $("##{@id}").length
193
- $(window).scroll ->
299
+ $("window,.pink-yield").scroll ->
194
300
  unless Pinkman._stopScroll
195
301
  Pinkman._stopScroll = yes
196
302
  callback(window.scrollY)
@@ -33,7 +33,12 @@ class window.PinkmanPath extends Pinkman.object
33
33
  @set('staticDepth',s)
34
34
  @set('dynamicDepth',d)
35
35
 
36
-
36
+ @depth: (url) ->
37
+ a = url.split('/')
38
+ a.shift() if a[0] == ''
39
+ a.pop() if a[a.length-1] == ''
40
+ a.length
41
+
37
42
  @isExternal: (url) ->
38
43
  urlRegex = new RegExp('^(?:[a-z]+:)?//', 'i')
39
44
  hostRegex = new RegExp(window.location.origin,'i')
@@ -54,13 +59,13 @@ class window.PinkmanPath extends Pinkman.object
54
59
  match = true
55
60
  @static.each (level) ->
56
61
  match = false if level.entry != path.level(level.index).entry
57
- if match
58
- @dynamic.each (level) ->
59
- path.params[level.entry.replace(/:/g,"")] = path.level(level.index).entry
60
62
  return(match)
61
63
  else
62
64
  false
63
-
65
+
66
+ matchParams: (path) ->
67
+ @dynamic.each (level) ->
68
+ path.params[level.entry.replace(/:/g,"")] = path.level(level.index).entry
64
69
 
65
70
  deduceControllerName: ->
66
71
  @static.extract('entry').join('-').replace(/[\/_]/g,'-').replace(/^-/,'')
@@ -86,24 +91,35 @@ class window.PinkmanRouteMatcher extends Pinkman.object
86
91
  $(@yieldIn).html("<div class='pink-yield' id='#{@controller}'></div>") if @yieldIn and @route.blank
87
92
 
88
93
  match: (url) ->
89
- path = new PinkmanPath(url)
90
- if path?
91
- candidates = Pinkman.routes.select(depth: path.depth)
92
- routes = candidates.select (candidate) ->
93
- candidate.path.match(path)
94
- route = routes.sortBy('staticDepth','desc').first()
94
+ if url?
95
+ route = @findRouteFor(url)
95
96
  if route?
96
- @set('url',url)
97
- @set('path',path)
98
- @set 'route', route
99
- @set 'controller', @route.controller
100
- @set('controllers', Pinkman.controllers.select(id: @controller))
101
- if @controllers.any()
102
- return(this)
103
- else
104
- throw "(Pinkman Route) Controller '#{@route.controller}' not found."
97
+ return(@setup(route,url))
105
98
  else
106
- return(false)
99
+ return(false)
100
+
101
+ findRouteFor: (url) ->
102
+ url = url.replace(window.location.origin,'') if PinkmanPath.isInternal(url)
103
+ return Pinkman.routes
104
+ .select(depth: PinkmanPath.depth(url))
105
+ .select((candidate) -> candidate.path.match(url))
106
+ .sortBy('staticDepth','desc').first()
107
+
108
+ setup: (route,url) ->
109
+ if route? and url?
110
+ urlPath = new PinkmanPath(url)
111
+ route.path.matchParams(urlPath)
112
+ @set('url',url)
113
+ @set('path',urlPath)
114
+ @set 'route', route
115
+ @set 'controller', @route.controller
116
+ @set('controllers', Pinkman.controllers.select(id: @controller))
117
+ if @controllers.any()
118
+ return(this)
119
+ else
120
+ throw "(Pinkman Route) Controller '#{@route.controller}' not found."
121
+ else
122
+ return(false)
107
123
 
108
124
  params: ->
109
125
  # console.log @path
@@ -230,6 +246,7 @@ class window.PinkmanRouter
230
246
  @activate: (path,callback,options) ->
231
247
  r = Pinkman.routes.match(path)
232
248
  if r? and r
249
+ # console.log r
233
250
  r.options = options
234
251
  if @_config.transition? and typeof @_config.transition == 'function'
235
252
  @_config.transition =>
@@ -274,10 +291,10 @@ class window.PinkmanRouter
274
291
  App.router = this
275
292
  window.$r = App.router
276
293
  @activate(window.location.pathname)
277
- $('body').on 'click', 'a:not([data-pinkman="false"])', (ev) =>
294
+ $('body').on 'click', 'a:not([data-pinkman="false"],[target="blank"],[target="_blank"])', (ev) =>
278
295
  ev.preventDefault()
279
296
  path = ev.currentTarget.href
280
- (window.location = path) unless path? and @visit(path)
297
+ @location(path) unless path? and @visit(path)
281
298
 
282
299
  namespace: (namespace, rules) ->
283
300
  namespace = namespace.replace(/^\//,'')
@@ -13,8 +13,8 @@ class window.PinkmanState extends Pinkman.object
13
13
 
14
14
  @initialize: ->
15
15
  if Pinkman.states.empty() and window? and history? and history.replaceState?
16
- state = Pinkman.states.forceNew(path: window.location.pathname)
17
- history.replaceState({pinkey: state.pinkey}, "", state.path)
16
+ state = Pinkman.states.forceNew(path: window.location.href.replace(window.location.origin,''))
17
+ # history.replaceState({pinkey: state.pinkey}, "", state.path)
18
18
 
19
19
  @push: (path) ->
20
20
  if Pinkman.isString(path)
@@ -1,4 +1,4 @@
1
1
  .form-field
2
2
  label for=attr_name = label
3
- == p.input input_options
3
+ == p.input html_attributes
4
4
  == p.error_for attr_name, label
@@ -1,6 +1,6 @@
1
1
  .form-field
2
2
  label for=attr_name = label
3
- == p.select attr_name, html_options
3
+ == p.select attr_name, html_attributes
4
4
  - if placeholder
5
5
  - if obligatory.present?
6
6
  option value="" selected='selected' disabled='disabled' = placeholder
@@ -9,55 +9,48 @@ module Pinkman
9
9
 
10
10
  include Pinkman::ViewsHelpers::FormHelper
11
11
 
12
- define_helper :string do |attr_name,label=nil|
13
- label ||= attr_name.titleize
14
- render partial: 'pinkman/pinkman/form_input', locals: {attr_name: attr_name, label: label, input_options: {name: attr_name}}
12
+ define_helper :string do |attr_name,label=nil,html_attributes={}|
13
+ p.input_helper attr_name, label, html_attributes.merge(type: 'text')
15
14
  end
16
15
 
17
- define_helper :text do |attr_name,label=nil|
16
+ define_helper :text do |attr_name,label=nil,html_attributes={}|
18
17
  label ||= attr_name.titleize
19
- render partial: 'pinkman/pinkman/form_textarea', locals: {attr_name: attr_name, label: label, textarea_options: {name: attr_name}}
18
+ render partial: 'pinkman/pinkman/form_textarea', locals: {attr_name: attr_name, label: label, textarea_options: {name: attr_name}.merge(html_attributes) }
20
19
  end
21
20
 
22
- define_helper :date do |attr_name,label=nil|
23
- label ||= attr_name.titleize
24
- render partial: 'pinkman/pinkman/form_input', locals: {attr_name: attr_name, label: label, input_options: {name: attr_name, type: 'date'}}
21
+ define_helper :date do |attr_name,label=nil,html_attributes={}|
22
+ p.input_helper attr_name, label, html_attributes.merge(type: 'date')
25
23
  end
26
24
 
27
- define_helper :datetime do |attr_name,label=nil|
28
- label ||= attr_name.titleize
29
- render partial: 'pinkman/pinkman/form_input', locals: {attr_name: attr_name, label: label, input_options: {name: attr_name}, type: 'time'}
25
+ define_helper :datetime do |attr_name,label=nil,html_attributes={}|
26
+ p.input_helper attr_name, label, html_attributes.merge(type: 'time')
30
27
  end
31
28
 
32
- define_helper :color do |attr_name,label=nil|
33
- label ||= attr_name.titleize
34
- render partial: 'pinkman/pinkman/form_input', locals: {attr_name: attr_name, label: label, input_options: {name: attr_name}}
29
+ define_helper :color do |attr_name,label=nil,html_attributes={}|
30
+ p.input_helper attr_name, label, html_attributes
35
31
  end
36
32
 
37
- define_helper :select do |attr_name,label,options_hash,html_options={}|
38
- if html_options.has_key?(:placeholder)
39
- placeholder = html_options[:placeholder]
40
- obligatory = html_options[:obligatory]
41
- html_options.delete(:placeholder)
33
+ define_helper :select do |attr_name,label,options_hash,html_attributes={}|
34
+ if html_attributes.has_key?(:placeholder)
35
+ placeholder = html_attributes[:placeholder]
36
+ obligatory = html_attributes[:obligatory]
37
+ html_attributes.delete(:placeholder)
42
38
  end
43
39
  obligatory = true if obligatory.nil?
44
40
  label ||= attr_name.titleize
45
- render partial: 'pinkman/pinkman/form_select', locals: {attr_name: attr_name, label: label, options_hash: options_hash, html_options: html_options, placeholder: placeholder, obligatory: obligatory}
41
+ render partial: 'pinkman/pinkman/form_select', locals: {attr_name: attr_name, label: label, options_hash: options_hash, html_attributes: html_attributes, placeholder: placeholder, obligatory: obligatory}
46
42
  end
47
43
 
48
- define_helper :password do |attr_name,label=nil|
49
- label ||= attr_name.titleize
50
- render partial: 'pinkman/pinkman/form_input', locals: {attr_name: attr_name, label: label, input_options: {name: attr_name, type: 'password'}}
44
+ define_helper :password do |attr_name,label=nil,html_attributes={}|
45
+ p.input_helper attr_name, label, html_attributes.merge(type: 'password')
51
46
  end
52
47
 
53
- define_helper :number do |attr_name,label=nil|
54
- label ||= attr_name.titleize
55
- render partial: 'pinkman/pinkman/form_input', locals: {attr_name: attr_name, label: label, input_options: {name: attr_name, type: 'number'}}
48
+ define_helper :number do |attr_name,label=nil,html_attributes={}|
49
+ p.input_helper attr_name, label, html_attributes.merge(type: 'number')
56
50
  end
57
51
 
58
- define_helper :money do |attr_name,label=nil|
59
- label ||= attr_name.titleize
60
- render partial: 'pinkman/pinkman/form_input', locals: {attr_name: attr_name, label: label, input_options: {name: attr_name, type: 'number', min: 0, step: 0.01}}
52
+ define_helper :money do |attr_name,label=nil,html_attributes={}|
53
+ p.input_helper attr_name, label, html_attributes.merge(type: 'number', min: '0', step: '0.01')
61
54
  end
62
55
 
63
56
  end
@@ -1,3 +1,3 @@
1
1
  module Pinkman
2
- VERSION = "0.9.9.9.0"
2
+ VERSION = "0.9.9.9.1"
3
3
  end
@@ -6,6 +6,11 @@ module Pinkman
6
6
 
7
7
  extend Pinkman::BaseHelper
8
8
 
9
+ define_helper :input_helper do |attr_name,label=nil,html_attributes={}|
10
+ label ||= attr_name.titleize
11
+ render partial: 'pinkman/pinkman/form_input', locals: {attr_name: attr_name, label: label, html_attributes: html_attributes.merge(name: attr_name)}
12
+ end
13
+
9
14
  define_helper :textfield do |attr_name,label=nil|
10
15
  label ||= attr_name.titleize
11
16
  render partial: 'pinkman/pinkman/form_input', locals: {attr_name: attr_name, label: label, input_options: {name: attr_name}}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pinkman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9.9.0
4
+ version: 0.9.9.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Agilso Oliveira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-06 00:00:00.000000000 Z
11
+ date: 2018-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler