tbone 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/assets/javascripts/tbone_backbone_datalink.js.coffee +44 -0
- data/app/assets/javascripts/views/common/form_part_view.js.coffee +9 -0
- data/app/assets/javascripts/views/common/form_view.js.coffee +16 -10
- data/lib/tbone/engine.rb +2 -2
- data/tbone.gemspec +4 -2
- metadata +11 -9
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
@@ -0,0 +1,44 @@
|
|
1
|
+
(($) ->
|
2
|
+
$.extend $.fn,
|
3
|
+
backboneLink: (model) ->
|
4
|
+
form = $(this)
|
5
|
+
renameInputs = (cid, name) ->
|
6
|
+
$('*[name="' + name + '"]:input', form).attr('name', name + '_' + cid)
|
7
|
+
|
8
|
+
getInputs = (cid, name) ->
|
9
|
+
$('*[name="' + name + '_' + cid + '"]:input', form)
|
10
|
+
|
11
|
+
setValue = (cid, name, value) ->
|
12
|
+
inputs = getInputs(cid, name)
|
13
|
+
return if inputs.length == 0
|
14
|
+
input = $(inputs[0])
|
15
|
+
if (input.is('input') && input.attr('type') == 'text') || input.is('textarea')
|
16
|
+
input.val(value)
|
17
|
+
if input.is('input') && input.attr('type') == 'radio'
|
18
|
+
inputs.filter('[value="' + value + '"]').attr('checked', true)
|
19
|
+
if input.is('select')
|
20
|
+
options = $('option', input)
|
21
|
+
options.filter('[value="' + value + '"]').attr('selected', true)
|
22
|
+
|
23
|
+
getValue = (inputs) ->
|
24
|
+
input = $(inputs[0]) if inputs.length > 0
|
25
|
+
val = null
|
26
|
+
if (input.is('input') && input.attr('type') == 'text') || input.is('textarea')
|
27
|
+
val = input.val()
|
28
|
+
if input.is('input') && input.attr('type') == 'radio'
|
29
|
+
val = inputs.filter(':checked').val()
|
30
|
+
if input.is('select')
|
31
|
+
val = $('option:selected', input).val()
|
32
|
+
val
|
33
|
+
|
34
|
+
$.each model.attributes, (name, value) ->
|
35
|
+
renameInputs(model.cid, name)
|
36
|
+
setValue(model.cid, name, value)
|
37
|
+
model.bind 'change:' + name, ->
|
38
|
+
setValue(model.cid, name, model.get(name))
|
39
|
+
inputs = getInputs(model.cid, name)
|
40
|
+
inputs.bind 'change', (e) =>
|
41
|
+
el = $(e.target)
|
42
|
+
model.set(name, getValue(el))
|
43
|
+
|
44
|
+
) jQuery
|
@@ -7,11 +7,15 @@ define [
|
|
7
7
|
|
8
8
|
class App.Views.Common.FormView extends AlertView
|
9
9
|
events: ->
|
10
|
-
|
11
|
-
|
10
|
+
'submit': 'save'
|
11
|
+
'click .back': 'back'
|
12
12
|
|
13
13
|
initialize: ->
|
14
|
-
@model.on(
|
14
|
+
@model.on('change:errors', @renderErrors, this)
|
15
|
+
@on 'databind', @databind, @
|
16
|
+
|
17
|
+
databind: ->
|
18
|
+
|
15
19
|
|
16
20
|
cleanErrors: ->
|
17
21
|
@form.find(".error").removeClass("error")
|
@@ -39,13 +43,14 @@ define [
|
|
39
43
|
@model.set({errors: $.parseJSON(jqXHR.responseText)})
|
40
44
|
|
41
45
|
markErrorField: (name, error) ->
|
42
|
-
field = @form.find(":input[name=" + name + "]")
|
43
|
-
field.
|
44
|
-
|
46
|
+
field = @form.find(":input[name=" + name + '_' + @model.cid + "]")
|
47
|
+
controlGroup = field.parents('.control-group')
|
48
|
+
controlGroup.append("<div class='help-block'>" + error + "</div>")
|
49
|
+
controlGroup.addClass("error")
|
45
50
|
|
46
51
|
renderErrors: ->
|
47
52
|
@errors = @model.get('errors')
|
48
|
-
@form =
|
53
|
+
@form = $(@el)
|
49
54
|
@cleanErrors()
|
50
55
|
if @errors?
|
51
56
|
if @errors.error?
|
@@ -57,9 +62,10 @@ define [
|
|
57
62
|
render: ->
|
58
63
|
$(@el).html(@template(@model.toJSON() ))
|
59
64
|
@renderAlerts()
|
60
|
-
|
65
|
+
@trigger('databind')
|
66
|
+
@form = $(@el)
|
67
|
+
@form.backboneLink(@model)
|
61
68
|
return this
|
62
69
|
|
63
|
-
back:
|
64
|
-
e.preventDefault()
|
70
|
+
back: ->
|
65
71
|
window.history.back()
|
data/lib/tbone/engine.rb
CHANGED
@@ -9,8 +9,8 @@ module Tbone
|
|
9
9
|
'exports' => 'Backbone'
|
10
10
|
},
|
11
11
|
'backbone_rails_sync' => ['backbone'],
|
12
|
-
'
|
13
|
-
'backbone-rails' => ['backbone', 'backbone_rails_sync', '
|
12
|
+
'tbone_backbone_datalink' => ['backbone'],
|
13
|
+
'backbone-rails' => ['backbone', 'backbone_rails_sync', 'tbone_backbone_datalink']
|
14
14
|
},
|
15
15
|
'wrap' => true
|
16
16
|
}
|
data/tbone.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{tbone}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Pavel Tatarsky}]
|
12
|
-
s.date = %q{2012-07-
|
12
|
+
s.date = %q{2012-07-18}
|
13
13
|
s.description = %q{Library for mixing together requirejs backbone and twitter bootstrap}
|
14
14
|
s.email = %q{fazzzenda@mail.ru}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"app/assets/javascripts/models/.gitkeep",
|
33
33
|
"app/assets/javascripts/models/token.js.coffee",
|
34
34
|
"app/assets/javascripts/tbone.js.coffee",
|
35
|
+
"app/assets/javascripts/tbone_backbone_datalink.js.coffee",
|
35
36
|
"app/assets/javascripts/templates/.gitkeep",
|
36
37
|
"app/assets/javascripts/templates/common/alert_message.jst.hamljs",
|
37
38
|
"app/assets/javascripts/templates/common/confirm.jst.hamljs",
|
@@ -40,6 +41,7 @@ Gem::Specification.new do |s|
|
|
40
41
|
"app/assets/javascripts/views/common/alert_message_view.js.coffee",
|
41
42
|
"app/assets/javascripts/views/common/alert_view.js.coffee",
|
42
43
|
"app/assets/javascripts/views/common/confirm_view.js.coffee",
|
44
|
+
"app/assets/javascripts/views/common/form_part_view.js.coffee",
|
43
45
|
"app/assets/javascripts/views/common/form_view.js.coffee",
|
44
46
|
"app/assets/javascripts/views/common/pager_view.js.coffee",
|
45
47
|
"app/assets/javascripts/views/tokens/show_view.js.coffee",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tbone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
16
|
-
requirement: &
|
16
|
+
requirement: &70351195489060 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70351195489060
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70351195870520 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70351195870520
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jeweler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70351195870040 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70351195870040
|
47
47
|
description: Library for mixing together requirejs backbone and twitter bootstrap
|
48
48
|
email: fazzzenda@mail.ru
|
49
49
|
executables: []
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- app/assets/javascripts/models/.gitkeep
|
68
68
|
- app/assets/javascripts/models/token.js.coffee
|
69
69
|
- app/assets/javascripts/tbone.js.coffee
|
70
|
+
- app/assets/javascripts/tbone_backbone_datalink.js.coffee
|
70
71
|
- app/assets/javascripts/templates/.gitkeep
|
71
72
|
- app/assets/javascripts/templates/common/alert_message.jst.hamljs
|
72
73
|
- app/assets/javascripts/templates/common/confirm.jst.hamljs
|
@@ -75,6 +76,7 @@ files:
|
|
75
76
|
- app/assets/javascripts/views/common/alert_message_view.js.coffee
|
76
77
|
- app/assets/javascripts/views/common/alert_view.js.coffee
|
77
78
|
- app/assets/javascripts/views/common/confirm_view.js.coffee
|
79
|
+
- app/assets/javascripts/views/common/form_part_view.js.coffee
|
78
80
|
- app/assets/javascripts/views/common/form_view.js.coffee
|
79
81
|
- app/assets/javascripts/views/common/pager_view.js.coffee
|
80
82
|
- app/assets/javascripts/views/tokens/show_view.js.coffee
|
@@ -128,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
130
|
version: '0'
|
129
131
|
segments:
|
130
132
|
- 0
|
131
|
-
hash:
|
133
|
+
hash: 1740112795785978946
|
132
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
135
|
none: false
|
134
136
|
requirements:
|