material_raingular 0.0.2.5 → 0.0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/assets/javascripts/directives/mdupdate.coffee +64 -0
- data/lib/assets/javascripts/directives/ngboolean.js.coffee +6 -29
- data/lib/assets/javascripts/directives/ngcallback.coffee +17 -0
- data/lib/assets/javascripts/directives/ngtrackby.coffee +11 -0
- data/lib/assets/javascripts/directives/ngupdate.js.coffee +3 -83
- data/lib/assets/javascripts/material_raingular.js.coffee +5 -4
- data/lib/assets/javascripts/rails_updater.coffee +34 -0
- data/lib/material_raingular/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d682da46b3c4eec8b890748878f6fe659630de5
|
4
|
+
data.tar.gz: 9ad820a90a90c83604ef0d3192e8024385af0587
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bc1fc38c5aa76ba7886b27dc5980219f2bb41d1104b953540226e866da88be660db80c6d5f270511c8dee6b99f7dac41066a4f0211dbe72560d3b43f13c5e94
|
7
|
+
data.tar.gz: 88593dbecd75b04f400b4139ffccc2face2a02ed746c8090612662b049c515563086fc4f02a31c76eaf1d45a9eddb35fd3211c8c4db741eee94a1e07729ffe8c
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class ElementUpdate
|
2
|
+
constructor: (scope,element,attributes,controllers,RailsUpdater) ->
|
3
|
+
[@ngModelCtrl,@ngCallbackCtrl,@ngTrackByCtrl] = controllers
|
4
|
+
@updater = RailsUpdater.new(scope,controllers,attributes.ngModel,attributes.ngOverride)
|
5
|
+
@type = attributes.type
|
6
|
+
@tagName = element[0].tagName
|
7
|
+
@modelName = attributes.ngModel
|
8
|
+
@isInput = @tagName == 'INPUT'
|
9
|
+
@scope = scope
|
10
|
+
@element = element
|
11
|
+
@placeholder = attributes.placeholder
|
12
|
+
@bindInput() if @isInput
|
13
|
+
@bindElement() unless @isInput
|
14
|
+
@setPlaceholder() unless @placeholder
|
15
|
+
watcher: ->
|
16
|
+
eu = @
|
17
|
+
@scope.$watch @modelName, (updated,old) ->
|
18
|
+
eu.updater.update(updated) unless updated == old
|
19
|
+
bindInput: ->
|
20
|
+
eu = @
|
21
|
+
if @type == 'radio' || @type == 'date'
|
22
|
+
@element.bind 'input', (event) ->
|
23
|
+
return unless eu.ngModelCtrl.$valid
|
24
|
+
eu.updater.update(element.val())
|
25
|
+
else if @type == 'hidden'
|
26
|
+
@watcher()
|
27
|
+
else if @type == 'checkbox'
|
28
|
+
@element.bind 'click', (event) ->
|
29
|
+
eu.updater.update(element.val())
|
30
|
+
else
|
31
|
+
oldValue = null
|
32
|
+
@element.bind 'focus', ->
|
33
|
+
eu.scope.$apply ->
|
34
|
+
oldValue = eu.element.val()
|
35
|
+
@element.bind 'blur', (event) ->
|
36
|
+
delay = if @element.hasClass('autocomplete') then 300 else 0
|
37
|
+
$timeout ->
|
38
|
+
@scope.$apply ->
|
39
|
+
newValue = @element.val()
|
40
|
+
@updater.update(newValue) if (newValue != oldValue)
|
41
|
+
, delay
|
42
|
+
|
43
|
+
bindElement: ->
|
44
|
+
if @tagName == 'TEXTAREA'
|
45
|
+
@element.bind 'keyup', ->
|
46
|
+
$timeout.cancel(scope.debounce)
|
47
|
+
scope.debounce = $timeout ->
|
48
|
+
eu.updater.update(element.val())
|
49
|
+
,750
|
50
|
+
else
|
51
|
+
@watcher()
|
52
|
+
setPlaceholder: ->
|
53
|
+
placeholder = ''
|
54
|
+
for word in @modelName.split('.').pop().split('_')
|
55
|
+
placeholder += word[0].toUpperCase() + word[1..-1].toLowerCase() + ' '
|
56
|
+
@element.attr('placeholder',placeholder)
|
57
|
+
|
58
|
+
angular.module 'MdUpdate', ['Factories', 'FactoryName','RailsUpdater']
|
59
|
+
.directive 'mdUpdate', ($timeout, factoryName, $injector, RailsUpdater) ->
|
60
|
+
restrict: 'A'
|
61
|
+
require: ['ngModel','?ngCallback','?ngTrackBy']
|
62
|
+
|
63
|
+
link: (scope, element, attributes, ngControllers) ->
|
64
|
+
new ElementUpdate(scope,element,attributes,ngControllers, RailsUpdater)
|
@@ -1,33 +1,10 @@
|
|
1
|
-
angular.module 'NgBoolean', ['Factories', 'FactoryName']
|
1
|
+
angular.module 'NgBoolean', ['Factories', 'FactoryName','RailsUpdater']
|
2
2
|
|
3
|
-
.directive 'ngBoolean', ($injector,factoryName) ->
|
3
|
+
.directive 'ngBoolean', ($injector,factoryName,RailsUpdater) ->
|
4
4
|
restrict: 'A'
|
5
|
-
require: 'ngModel'
|
5
|
+
require: ['ngModel','?ngCallback','?ngTrackBy']
|
6
6
|
|
7
|
-
link: (scope, element, attributes,
|
8
|
-
|
9
|
-
callFunction = model + ' = !' + model + ' ; update("' + model + '")'
|
10
|
-
callFunction += ';' + attributes.ngCallback if attributes.ngCallback
|
11
|
-
element.attr("call-function", callFunction)
|
7
|
+
link: (scope, element, attributes, ngControllers) ->
|
8
|
+
updater = RailsUpdater.new(scope,ngControllers,attributes.ngModel,attributes.ngOverride)
|
12
9
|
element.bind 'click', ->
|
13
|
-
|
14
|
-
scope.update = (modelName)->
|
15
|
-
input = modelName.split(',')
|
16
|
-
trackby = input.pop() if input.length > 1
|
17
|
-
trackby = trackby.split(';') if trackby
|
18
|
-
trackby = [] unless trackby
|
19
|
-
data = input.splice(0,1)[0].split('.')
|
20
|
-
functions = input.join(',').split(')')
|
21
|
-
factory = factoryName(data[0])
|
22
|
-
object = {id: scope[data[0]]['id']}
|
23
|
-
object[data[0]] = {id: scope[data[0]]['id']}
|
24
|
-
object[data[0]][data[1]] = scope[data[0]][data[1]]
|
25
|
-
list = $injector.get(factory)
|
26
|
-
list.update object, (returnData) ->
|
27
|
-
for tracked in trackby
|
28
|
-
scope[data[0]][tracked] = returnData[tracked]
|
29
|
-
ngModelCtrl.$setViewValue(returnData[data[1]]) if ngModelCtrl.$modelValue == object[data[0]][data[1]]
|
30
|
-
callFunctions = []
|
31
|
-
for callFunction in functions
|
32
|
-
callFunctions.push(callFunction + ',' + JSON.stringify(returnData) + ')') if callFunction.length > 0
|
33
|
-
scope.$eval( callFunctions.join('') ) if callFunctions.join('').length > 0
|
10
|
+
updater.update(element.val())
|
@@ -0,0 +1,17 @@
|
|
1
|
+
angular.module 'NgCallback', ['Factories', 'FactoryName']
|
2
|
+
|
3
|
+
.directive 'ngCallback', ->
|
4
|
+
restrict: 'A'
|
5
|
+
controller: ($scope,$element) ->
|
6
|
+
@evaluate = (returnData)->
|
7
|
+
for callback in $element[0].attributes['ng-callback'].value.split(';')
|
8
|
+
[match,func,args] = callback.match(/(.*)\((.*)\)/)
|
9
|
+
data = []
|
10
|
+
for arg in args.split(',')
|
11
|
+
data.push $scope.$eval(arg)
|
12
|
+
data.push returnData
|
13
|
+
if typeof $scope[func] == 'function'
|
14
|
+
$scope[func] data...
|
15
|
+
else if typeof window[func] == 'function'
|
16
|
+
window[func] data...
|
17
|
+
return
|
@@ -0,0 +1,11 @@
|
|
1
|
+
angular.module 'NgTrackBy', ['Factories', 'FactoryName']
|
2
|
+
|
3
|
+
.directive 'ngTrackBy', ->
|
4
|
+
restrict: 'A'
|
5
|
+
|
6
|
+
controller: ($scope,$element) ->
|
7
|
+
@evaluate = (returnData)->
|
8
|
+
parent = attributes['ng-model'].value.split('.')[0]
|
9
|
+
for model in $element[0].attributes['ng-track-by'].value.split(';')
|
10
|
+
$scope[parent][model] = returnData[model]
|
11
|
+
return
|
@@ -2,8 +2,9 @@ angular.module 'NgUpdate', ['Factories', 'FactoryName']
|
|
2
2
|
|
3
3
|
.directive 'ngUpdate', ($timeout, $compile) ->
|
4
4
|
restrict: 'A'
|
5
|
+
require: '?ngCallback'
|
5
6
|
|
6
|
-
link: (scope, element, attributes,
|
7
|
+
link: (scope, element, attributes, ngCallbackCtrl) ->
|
7
8
|
model = attributes.ngUpdate.split('"').join('\'')
|
8
9
|
html = element[0].outerHTML
|
9
10
|
html = angular.element(html)
|
@@ -17,7 +18,6 @@ angular.module 'NgUpdate', ['Factories', 'FactoryName']
|
|
17
18
|
placeholder += word[0].toUpperCase() + word[1..-1].toLowerCase() + ' '
|
18
19
|
callModel += ',' + attributes.ngTrackBy if attributes.ngTrackBy
|
19
20
|
callFunction = 'update("' + callModel + '")'
|
20
|
-
callFunction += ';' + attributes.ngCallback if attributes.ngCallback
|
21
21
|
if element[0].tagName == 'INPUT'
|
22
22
|
html[0].setAttribute("ng-change-on-blur", callFunction) if attributes.type != 'radio' && attributes.type != 'checkbox' && attributes.type != 'hidden'
|
23
23
|
html[0].setAttribute("ng-change", callFunction) unless attributes.type != 'radio' && attributes.type != 'checkbox' && attributes.type != 'hidden'
|
@@ -27,7 +27,6 @@ angular.module 'NgUpdate', ['Factories', 'FactoryName']
|
|
27
27
|
html[0].setAttribute("ng-change-debounce", callFunction)
|
28
28
|
else
|
29
29
|
callFunction = callModel + ' = !' + callModel + ' ; update("' + callModel + '")'
|
30
|
-
callFunction += ';' + attributes.ngCallback if attributes.ngCallback
|
31
30
|
html[0].setAttribute("ng-click", callFunction)
|
32
31
|
html[0].setAttribute('placeholder',placeholder)
|
33
32
|
html[0].removeAttribute('ng-update')
|
@@ -60,83 +59,4 @@ angular.module 'NgUpdate', ['Factories', 'FactoryName']
|
|
60
59
|
for callFunction in functions
|
61
60
|
callFunctions.push(callFunction + ',' + JSON.stringify(returnData) + ')') if callFunction.length > 0
|
62
61
|
$scope.$eval( callFunctions.join('') ) if callFunctions.join('').length > 0
|
63
|
-
|
64
|
-
.directive 'mdUpdate', ($timeout, factoryName, $injector) ->
|
65
|
-
restrict: 'A'
|
66
|
-
require: 'ngModel'
|
67
|
-
|
68
|
-
link: (scope, element, attributes, ngModelCtrl) ->
|
69
|
-
modelName = attributes.ngModel
|
70
|
-
watcher = ->
|
71
|
-
scope.$watch modelName, (updated,old) ->
|
72
|
-
update(updated) unless updated == old
|
73
|
-
equiv = (left,right) ->
|
74
|
-
return true if left == right
|
75
|
-
return true if (!!left && !!right) == false
|
76
|
-
false
|
77
|
-
|
78
|
-
update = (value) ->
|
79
|
-
override = if attributes.ngOverride then attributes.ngOverride.split('.') else []
|
80
|
-
functions = if attributes.ngCallback then attributes.ngCallback.split(';') else []
|
81
|
-
trackby = if attributes.ngTrackBy then attributes.ngTrackBy.split(';') else []
|
82
|
-
data = modelName.split('.')
|
83
|
-
factory = factoryName(override[0] || data[0])
|
84
|
-
if override[1]
|
85
|
-
object = {id: scope.$eval(override[0]).id}
|
86
|
-
object[override[1]] = scope.$eval(override[1])
|
87
|
-
else
|
88
|
-
object = {id: scope[data[0]]['id']}
|
89
|
-
object[data[0]] = {id: scope[data[0]]['id']}
|
90
|
-
object[data[0]][data[1]] = scope[data[0]][data[1]]
|
91
|
-
object[data[0]].lock_version = scope[data[0]].lock_version
|
92
|
-
list = $injector.get(factory)
|
93
|
-
|
94
|
-
unless scope[data[0]].currently_updating
|
95
|
-
scope[data[0]].currently_updating = true
|
96
|
-
list.update object, (returnData) ->
|
97
|
-
scope[data[0]].currently_updating = false
|
98
|
-
for tracked in trackby
|
99
|
-
scope[data[0]][tracked] = returnData[tracked]
|
100
|
-
scope[data[0]][data[1]] = returnData[data[1]] if equiv(scope[data[0]][data[1]], object[data[0]][data[1]]) && !equiv(scope[data[0]][data[1]], returnData[data[1]])
|
101
|
-
scope[data[0]].errors = returnData.errors
|
102
|
-
callFunctions = []
|
103
|
-
for callFunction in functions
|
104
|
-
[match,func,args] = callFunction.match(/(.*)\((.*)\)/)
|
105
|
-
if typeof scope[func] == 'function'
|
106
|
-
scope[func](args,returnData)
|
107
|
-
else if typeof window[func] == 'function'
|
108
|
-
window[func](args,returnData)
|
109
|
-
if element[0].tagName == 'INPUT'
|
110
|
-
if attributes.type == 'radio' || attributes.type == 'checkbox' || attributes.type == 'date'
|
111
|
-
element.bind 'input', (event) ->
|
112
|
-
return unless ngModelCtrl.$valid
|
113
|
-
update(element.val())
|
114
|
-
else if attributes.type == 'hidden'
|
115
|
-
watcher()
|
116
|
-
else
|
117
|
-
oldValue = null
|
118
|
-
element.bind 'focus', ->
|
119
|
-
scope.$apply ->
|
120
|
-
oldValue = element.val()
|
121
|
-
element.bind 'blur', (event) ->
|
122
|
-
delay = if element.hasClass('autocomplete') then 300 else 0
|
123
|
-
$timeout ->
|
124
|
-
scope.$apply ->
|
125
|
-
newValue = element.val()
|
126
|
-
update(newValue) if (newValue != oldValue)
|
127
|
-
, delay
|
128
|
-
else if element[0].tagName == 'TEXTAREA'
|
129
|
-
element.bind 'keyup', ->
|
130
|
-
$timeout.cancel(scope.debounce)
|
131
|
-
scope.debounce = $timeout ->
|
132
|
-
update(element.val())
|
133
|
-
,750
|
134
|
-
else
|
135
|
-
watcher()
|
136
|
-
if element[0].attributes['placeholder']
|
137
|
-
placeholder = element[0].attributes['placeholder'].value
|
138
|
-
else
|
139
|
-
placeholder = ''
|
140
|
-
for word in modelName.split('.').pop().split('_')
|
141
|
-
placeholder += word[0].toUpperCase() + word[1..-1].toLowerCase() + ' '
|
142
|
-
element.attr('placeholder',placeholder)
|
62
|
+
ngCallbackCtrl.evaluate(returnData) if !!ngCallbackCtrl
|
@@ -14,9 +14,10 @@
|
|
14
14
|
# //= require dateconverter
|
15
15
|
# //= require ajax_errors
|
16
16
|
# //= require identifier_interceptor
|
17
|
+
# //= require rails_updater
|
17
18
|
|
18
19
|
angular.module('materialRaingular', ['AutoComplete', 'NgDownload', 'NgChangeOnBlur', 'NgDrag', 'NgAuthorize'
|
19
|
-
'NgRepeatList', 'NgUpdate', 'NgPopup', 'NgBoolean', 'Table', 'NgWatchShow'
|
20
|
-
'NgUpload', 'NgDestroy', 'NgCreate', 'Video','NgAuthorize', 'TextArea'
|
21
|
-
'NgSlide', 'NgMatches','NgFade','NgSwipe', 'NgLoad', 'NgWatchContent'
|
22
|
-
'ngRoute', 'ngMaterial', 'ngMessages', 'ngResource', 'materialFilters'])
|
20
|
+
'NgRepeatList', 'NgUpdate', 'NgPopup', 'NgBoolean', 'Table', 'NgWatchShow', 'NgTrackBy'
|
21
|
+
'NgUpload', 'NgDestroy', 'NgCreate', 'Video','NgAuthorize', 'TextArea', 'MdUpdate'
|
22
|
+
'NgSlide', 'NgMatches','NgFade','NgSwipe', 'NgLoad', 'NgWatchContent', 'RailsUpdater'
|
23
|
+
'ngRoute', 'ngMaterial', 'ngMessages', 'ngResource', 'materialFilters', 'NgCallback'])
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class RailsUpdate
|
2
|
+
constructor: ($injector,factoryName,scope,controllers,model,override)->
|
3
|
+
@injector = $injector
|
4
|
+
@factoryName = factoryName
|
5
|
+
@scope = scope
|
6
|
+
@modelName = (override || model).split('.')[0]
|
7
|
+
@atomName = (override || model).split('.')[1]
|
8
|
+
@override = !!override
|
9
|
+
@factory = @injector.get(@factoryName(@modelName))
|
10
|
+
@object = {id: scope[@modelName].id}
|
11
|
+
@ngModelCtrl = controllers.shift()
|
12
|
+
@controllers = controllers
|
13
|
+
return @
|
14
|
+
equiv: (left,right) ->
|
15
|
+
return true if left == right
|
16
|
+
return true if (!!left && !!right) == false
|
17
|
+
false
|
18
|
+
update: (value) ->
|
19
|
+
@value = if @override then scope.$eval(@atomName) else value
|
20
|
+
@object[@atomName] = value
|
21
|
+
unless @scope[@modelName].currently_updating
|
22
|
+
@scope[@modelName].currently_updating = true
|
23
|
+
up = @
|
24
|
+
@factory.update @object, (returnData) ->
|
25
|
+
up.scope[up.modelName].currently_updating = false
|
26
|
+
unless up.equiv(up.ngModelCtrl.$viewValue,returnData[up.atomName])
|
27
|
+
up.ngModelCtrl.$setModelValue = returnData[up.atomName]
|
28
|
+
up.ngModelCtrl.$render()
|
29
|
+
for controller in up.controllers
|
30
|
+
controller.evaluate(returnData) if !!controller
|
31
|
+
angular.module 'RailsUpdater', ['Factories', 'FactoryName']
|
32
|
+
.factory 'RailsUpdater', ($injector,factoryName) ->
|
33
|
+
new: (scope,controllers,model,override)->
|
34
|
+
return new RailsUpdate($injector,factoryName,scope,controllers,model,override)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: material_raingular
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.2.
|
4
|
+
version: 0.0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Moody
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,9 +70,11 @@ files:
|
|
70
70
|
- lib/assets/javascripts/ajax_errors.js.coffee
|
71
71
|
- lib/assets/javascripts/dateconverter.coffee
|
72
72
|
- lib/assets/javascripts/dateparser.coffee
|
73
|
+
- lib/assets/javascripts/directives/mdupdate.coffee
|
73
74
|
- lib/assets/javascripts/directives/ngauthorize.js.coffee
|
74
75
|
- lib/assets/javascripts/directives/ngautocomplete.js.coffee
|
75
76
|
- lib/assets/javascripts/directives/ngboolean.js.coffee
|
77
|
+
- lib/assets/javascripts/directives/ngcallback.coffee
|
76
78
|
- lib/assets/javascripts/directives/ngchangeonblur.js.coffee
|
77
79
|
- lib/assets/javascripts/directives/ngcreate.js.coffee
|
78
80
|
- lib/assets/javascripts/directives/ngdestroy.js.coffee
|
@@ -85,6 +87,7 @@ files:
|
|
85
87
|
- lib/assets/javascripts/directives/ngrepeatlist.js.coffee
|
86
88
|
- lib/assets/javascripts/directives/ngslide.js.coffee
|
87
89
|
- lib/assets/javascripts/directives/ngswipe.js.coffee
|
90
|
+
- lib/assets/javascripts/directives/ngtrackby.coffee
|
88
91
|
- lib/assets/javascripts/directives/ngupdate.js.coffee
|
89
92
|
- lib/assets/javascripts/directives/ngupload.js.coffee
|
90
93
|
- lib/assets/javascripts/directives/ngwatchcontent.js.coffee
|
@@ -97,6 +100,7 @@ files:
|
|
97
100
|
- lib/assets/javascripts/identifier_interceptor.js.coffee
|
98
101
|
- lib/assets/javascripts/material_filters.coffee
|
99
102
|
- lib/assets/javascripts/material_raingular.js.coffee
|
103
|
+
- lib/assets/javascripts/rails_updater.coffee
|
100
104
|
- lib/material_raingular.rb
|
101
105
|
- lib/material_raingular/version.rb
|
102
106
|
- lib/tasks/material_raingular.rake
|