backbone_editable-rails 0.0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/backbone_editable-rails.gemspec +19 -0
- data/lib/assets/javascripts/backbone_editable.js.coffee +138 -0
- data/lib/backbone_editable/rails/engine.rb +9 -0
- data/lib/backbone_editable/rails/version.rb +5 -0
- data/lib/backbone_editable-rails.rb +5 -0
- metadata +71 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Geoff Harcourt
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# backbone_editable for Rails
|
2
|
+
|
3
|
+
backbone_editable via the Rails 3.1+ asset pipeline.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'backbone_editable-rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Add this line to your JS manifest file (application.js):
|
16
|
+
|
17
|
+
//= require backbone_editable
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Documentation on backbone_editable [here](https://github.com/matthewsmart/backbone-editable).
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
backbone_editable-rails maintained by [Geoff Harcourt](http://github.com/geoffharcourt)
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'backbone_editable/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.authors = ["Geoff Harcourt"]
|
8
|
+
gem.email = ["geoff.harcourt@gmail.com"]
|
9
|
+
gem.summary = %q{backbone_editable via asset pipeline}
|
10
|
+
gem.homepage = "http://github.com/geoffharcourt/backbone_editable-rails"
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "backbone_editable-rails"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = BackboneEditable::Rails::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'railties', '>= 3.1'
|
19
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
if not Function::mixin
|
2
|
+
Function::mixin = (module) ->
|
3
|
+
for name, method of module::
|
4
|
+
this::[name] = method
|
5
|
+
return this
|
6
|
+
if not Backbone.Mixin
|
7
|
+
Backbone.Mixin = {}
|
8
|
+
|
9
|
+
class Backbone.Mixin.Editable
|
10
|
+
_editable_events:
|
11
|
+
'click .editable' : '_editable'
|
12
|
+
'blur .editable input': '_setKey'
|
13
|
+
'keyup .editable input': '_setKeyEnter'
|
14
|
+
|
15
|
+
initEditable: (options = {}) ->
|
16
|
+
@_setSilent(options)
|
17
|
+
@events = {} unless @events
|
18
|
+
_.extend @events, @_editable_events
|
19
|
+
@delegateEvents()
|
20
|
+
|
21
|
+
|
22
|
+
_editable: (e) ->
|
23
|
+
$el = $(e.currentTarget)
|
24
|
+
if !$el.hasClass('editing')
|
25
|
+
# Gather data
|
26
|
+
width = $el.width()
|
27
|
+
value = Backbone.Mixin.Editable._GetValue
|
28
|
+
model: @model,
|
29
|
+
el: $el
|
30
|
+
# Set up the field
|
31
|
+
$el.addClass('editing').html('<input />').
|
32
|
+
find('input').val(value).
|
33
|
+
width(width).
|
34
|
+
focus()
|
35
|
+
|
36
|
+
_setKey: (e) ->
|
37
|
+
$el = $(e.currentTarget).parent()
|
38
|
+
if $el.hasClass('editing')
|
39
|
+
# Get the old value in case of an error
|
40
|
+
old_value = Backbone.Mixin.Editable._GetValue
|
41
|
+
model: @model,
|
42
|
+
el: $el
|
43
|
+
# Get the results of the edit
|
44
|
+
[key, value] = Backbone.Mixin.Editable._NewAttributes
|
45
|
+
model: @model,
|
46
|
+
value: $el.find('input').val(),
|
47
|
+
el: $el
|
48
|
+
# Save the model and remove the input if
|
49
|
+
# The settings were alright
|
50
|
+
@model.save key, value,
|
51
|
+
wait: true, silent: @_getSilent($el),
|
52
|
+
success: => @_removeInput($el),
|
53
|
+
error: (model, error) =>
|
54
|
+
$el.find('input').addClass('error').
|
55
|
+
val(old_value).
|
56
|
+
focus()
|
57
|
+
@model.trigger 'error', model, error
|
58
|
+
|
59
|
+
_removeInput: ($el) =>
|
60
|
+
# Get rid of the text box, and set the new
|
61
|
+
# (or old) value.
|
62
|
+
value = Backbone.Mixin.Editable._GetValue
|
63
|
+
model: @model,
|
64
|
+
el: $el
|
65
|
+
precision = $el.data 'precision'
|
66
|
+
if precision
|
67
|
+
value = parseFloat(value).toFixed(precision)
|
68
|
+
$el.removeClass('editing').html(value)
|
69
|
+
|
70
|
+
_setKeyEnter: (e) ->
|
71
|
+
if e.keyCode is 13
|
72
|
+
# Trigger the blur event
|
73
|
+
$(e.currentTarget).blur()
|
74
|
+
|
75
|
+
_getSilent: ($el) ->
|
76
|
+
el_silent = $el.data 'silent'
|
77
|
+
if (el_silent is @silent) or (el_silent is undefined)
|
78
|
+
@silent
|
79
|
+
else
|
80
|
+
el_silent
|
81
|
+
|
82
|
+
_setSilent: (options) ->
|
83
|
+
if options['silent_events'] or options['silent_events'] is undefined
|
84
|
+
@silent = true
|
85
|
+
else
|
86
|
+
@silent = false
|
87
|
+
|
88
|
+
|
89
|
+
@_GetValue = (options = {}) ->
|
90
|
+
model = options['model']
|
91
|
+
$el = options['el']
|
92
|
+
object = $el.data('object')
|
93
|
+
index = $el.data('index')
|
94
|
+
key = $el.data('key')
|
95
|
+
value = null
|
96
|
+
# Full complexity
|
97
|
+
if object and (index != undefined) and key
|
98
|
+
value = model.get(object)[index][key]
|
99
|
+
# Object with a key
|
100
|
+
else if object and key
|
101
|
+
value = model.get(object)[key]
|
102
|
+
# Object that is an array
|
103
|
+
else if object and (index != undefined)
|
104
|
+
value = model.get(object)[index]
|
105
|
+
# Just accessing by a key
|
106
|
+
else
|
107
|
+
value = model.get key
|
108
|
+
return value
|
109
|
+
|
110
|
+
@_NewAttributes = (options = {}) ->
|
111
|
+
model = options['model']
|
112
|
+
value = options['value']
|
113
|
+
silent = false
|
114
|
+
silent = true if options['silent']
|
115
|
+
$el = options['el']
|
116
|
+
object = $el.data('object')
|
117
|
+
index = $el.data('index')
|
118
|
+
key = $el.data('key')
|
119
|
+
# Full complexity
|
120
|
+
if object and (index != undefined) and key
|
121
|
+
new_object = _.clone model.get(object)
|
122
|
+
new_index = _.clone new_object[index]
|
123
|
+
new_index[key] = value
|
124
|
+
new_object[index] = new_index
|
125
|
+
[object, new_object]
|
126
|
+
# Object with a key
|
127
|
+
else if object and key
|
128
|
+
new_object = _.clone model.get(object)
|
129
|
+
new_object[key] = value
|
130
|
+
[object, new_object]
|
131
|
+
# Object that is an array
|
132
|
+
else if object and (index != undefined)
|
133
|
+
new_object = _.clone model.get(object)
|
134
|
+
new_object[index] = value
|
135
|
+
[object, new_object]
|
136
|
+
# Just accessing by a key
|
137
|
+
else
|
138
|
+
[key, value]
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: backbone_editable-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Geoff Harcourt
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.1'
|
30
|
+
description:
|
31
|
+
email:
|
32
|
+
- geoff.harcourt@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- backbone_editable-rails.gemspec
|
43
|
+
- lib/assets/javascripts/backbone_editable.js.coffee
|
44
|
+
- lib/backbone_editable-rails.rb
|
45
|
+
- lib/backbone_editable/rails/engine.rb
|
46
|
+
- lib/backbone_editable/rails/version.rb
|
47
|
+
homepage: http://github.com/geoffharcourt/backbone_editable-rails
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.24
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: backbone_editable via asset pipeline
|
71
|
+
test_files: []
|