material_raingular 0.0.5 → 0.0.6

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
  SHA1:
3
- metadata.gz: 03980b9a6d9bf6a3d71f36453f0f5eee0f399de8
4
- data.tar.gz: 6e5458e8885aa46d0b974f3065052d17cd3b0d03
3
+ metadata.gz: dd3b0de67560394702ab17c967af7ed1fc575b86
4
+ data.tar.gz: 5fb5ac84e3ada975ca03f737dbdfe4371702bc80
5
5
  SHA512:
6
- metadata.gz: e9c572a1c47ece8bbf2655d8ab03dc7c736fd37275b004440b4852c3fb6c221ca6e8d023fdcbd67175f0b518f82e0468c4f4375e9bd6be608d3d80356eed2761
7
- data.tar.gz: 115da2a6610b43fa3111186ed8f78a601937ddcc929d925436d5afc4d22f171f728500cd8a1cb10ff49445b8232c67cfca23d672dba9cbe5589c6fb0a13d36ad
6
+ metadata.gz: e5c74de317460b634fa55e7931c20f7d80bc656b50b3f3ccf90732a521479142073002ad529e591000ea89624d2b6371249588c8aab9fe54a3a3ef426ab9cd68
7
+ data.tar.gz: 6baa17e1247fd2977ff280707a98ffb1fdc63c454595c35cd5fde004a3a125f8931755b46bc7b8e33af617320c7c1785007baaa5f25b0c11a93fe82b954c2880
@@ -281,6 +281,12 @@ angular.module('FilteredSelect', [])
281
281
  if fieldset.length > 0
282
282
  ngdis = if fieldset[0].attributes.ngDisabled then fieldset[0].attributes.ngDisabled.value else ''
283
283
  return true if fieldset[0].attributes.disabled || $parse(ngdis)(scope)
284
+ form = element[0]
285
+ until form.nodeName == 'FORM' || !form
286
+ form = form.parentNode
287
+ break if !form
288
+ form ||= element[0]
289
+ return true if form.disabled
284
290
  return false
285
291
 
286
292
  viewOptions = JSON.parse(attrs.filterOptions || '{}')
@@ -5,6 +5,12 @@ angular.module 'NgDestroy', ['Factories']
5
5
  require: '?ngCallback'
6
6
  link: (scope, element, attributes, ngCallbackCtrl) ->
7
7
  element.bind 'click', (event) ->
8
+ form = element[0]
9
+ until form.nodeName == 'FORM' || !form
10
+ form = form.parentNode
11
+ break if !form
12
+ form ||= element[0]
13
+ return if attributes.disabled || form.disabled
8
14
  destroy(attributes.ngDestroy,attributes.ngContext)
9
15
  destroy = (modelName,listName) ->
10
16
  factory = factoryName(modelName)
@@ -1,151 +1,139 @@
1
- selectFile = (scope,event,attributes,file) ->
2
- model = attributes.ngModel.split('.')
3
- id = scope[attributes.ngModel.split('.')[0]].id
4
- parent = null
5
- if attributes.ngContext
6
- parent = attributes.ngContext
7
- scope.uploadFiles(model,id,file,parent)
8
- event.preventDefault()
1
+ class FileUpload
2
+ constructor: (@parse,@scope,controllers,model,override,@element)->
3
+ [@ngModel,@ngCallback] = controllers
4
+ modelName = (override || model)
5
+ if parts = modelName.match(/(.+)\[(.+)\]/)
6
+ @modelName = parts[1]
7
+ @atomName = @parse(parts[2])()
8
+ else
9
+ [@modelName,@atomName] = modelName.split('.')
10
+ @override = !!override
11
+ uploadFile: (file)->
12
+ @scope.progress = 0
13
+ @element.addClass('covered')
14
+ id = @scope.$eval(@modelName).id
15
+ route = Routes[@modelName + '_path'](id: id) + '.json'
16
+ formData = new FormData()
17
+ formData.append @modelName + '[id]', id
18
+ formData.append @modelName + '[' + @atomName + ']', file
19
+ xhr = new XMLHttpRequest()
20
+ xhr.upload.addEventListener "progress", (event) =>
21
+ if event.lengthComputable
22
+ @scope.$apply =>
23
+ @scope.progress = Math.round(event.loaded * 100 / event.total)
24
+ , true
25
+ xhr.addEventListener "readystatechange", (event) =>
26
+ if event.target.readyState == 4 && !(event.target.status > 399)
27
+ data = JSON.parse(event.target.response)
28
+ @scope.$apply =>
29
+ @scope[@modelName][@atomName] = data[@atomName]
30
+ @scope[@modelName].thumb = data.thumb
31
+ @scope.progress = 100
32
+ @element.removeClass('covered')
33
+ @ngCallback.evaluate(data) if !!@ngCallback
34
+ else if event.target.readyState == 4 && event.target.status > 399
35
+ failed()
36
+ , false
37
+ xhr.addEventListener "error", (event) ->
38
+ failed()
39
+ , false
40
+ failed = ->
41
+ @element.addClass('failed')
9
42
 
10
- fileData = (scope,attributes) ->
11
- data = {}
12
- unparsedModel = attributes.ngModel.split('.')
13
- if scope[unparsedModel[0]]
14
- if scope[unparsedModel[0]][unparsedModel[1]]
15
- unparsed = scope[unparsedModel[0]][unparsedModel[1]].location.split('/')
16
- name = unparsed.pop()
17
- id = unparsed.pop()
18
- mounted_as = unparsed.pop()
19
- model = unparsed.pop()
20
- data.path = scope[unparsedModel[0]][unparsedModel[1]].url
21
- data.name = name
22
- data.thumb = scope[unparsedModel[0]].thumb.url if scope[unparsedModel[0]].thumb
23
- return data
43
+ timeout ->
44
+ @element.removeClass('failed')
45
+ @element.removeClass('covered')
46
+ , 2000
24
47
 
25
- uploadFiles = (scope,element,model,id,file,parent,timeout,callback) ->
26
- scope.progress = 0
27
- element.addClass('covered')
28
- route = Routes[element[0].attributes['ng-model'].value.split('.')[0] + '_path'](id: id) + '.json'
29
- formData = new FormData()
30
- formData.append model[0] + '[id]', id
31
- formData.append model[0] + '[' + model[1] + ']', file
32
- formData.append model[0] + '[' + parent + '_id]', $scope[parent].id if parent
33
- xhr = new XMLHttpRequest()
34
- xhr.upload.addEventListener "progress", (event) ->
35
- if event.lengthComputable
36
- scope.$apply ->
37
- scope.progress = Math.round(event.loaded * 100 / event.total)
38
- , false
39
- xhr.addEventListener "readystatechange", (event) ->
40
- if this.readyState == 4 && !(this.status > 399)
41
- data = JSON.parse(event.target.response)
42
- scope.$apply ->
43
- scope[model[0]][model[1]] = data[model[1]]
44
- scope[model[0]].thumb = data.thumb
45
- scope.progress = 100
46
- element.removeClass('covered')
47
- scope.$eval(callback) if callback
48
- else if this.readyState == 4 && this.status > 399
49
- failed()
50
- , false
51
- xhr.addEventListener "error", (event) ->
52
- failed()
53
- , false
54
- failed = ->
55
- element.addClass('failed')
48
+ xhr.open("PUT", route)
49
+ csrf = null
50
+ for tag in document.getElementsByTagName('meta')
51
+ csrf = tag.content if tag.name == 'csrf-token'
52
+ xhr.setRequestHeader('X-CSRF-Token', csrf)
53
+ xhr.send(formData)
56
54
 
57
- timeout ->
58
- element.removeClass('failed')
59
- element.removeClass('covered')
60
- , 2000
55
+ fileData: ->
56
+ data = {}
57
+ if @scope[@modelName]
58
+ if @scope[@modelName][@atomName]
59
+ data.path = @scope[@modelName][@atomName].url
60
+ data.name = @scope[@modelName][@atomName].name
61
+ data.thumb = @scope[@modelName].thumb.url if @scope[@modelName].thumb
62
+ return data
61
63
 
62
- xhr.open("PUT", route)
63
- csrf = null
64
- for tag in document.getElementsByTagName('meta')
65
- csrf = tag.content if tag.name == 'csrf-token'
66
- xhr.setRequestHeader('X-CSRF-Token', csrf)
67
- xhr.send(formData)
64
+ class NgUploadEvents
65
+ constructor: (@element,@file_upload) ->
66
+ clicked = false
67
+ @element.children('img').bind 'click', (event) =>
68
+ return if clicked
69
+ event.target.parentElement.getElementsByTagName('input')[0].click()
70
+ @element.children('.button').bind 'click', (event) =>
71
+ return if clicked
72
+ event.target.parentElement.getElementsByTagName('input')[0].click()
73
+ @element.children('input').bind 'click', (event) =>
74
+ clicked = true
75
+ @element.children('input').bind 'change', (event) =>
76
+ file = event.target.files[0]
77
+ @file_upload.uploadFile(file)
78
+ clicked = false
79
+
80
+ class NgDropFileEvents
81
+ constructor: (@element,@file_upload) ->
82
+ dragHovered = 0
83
+ el = angular.element("<div class='hovered-cover'>Drop Files Here</div>")
84
+ @element.bind 'dragenter', (event) =>
85
+ dragHovered += 1
86
+ @element.addClass('hovered') if dragHovered == 1
87
+ @element.append el if dragHovered == 1
88
+ height = window.getComputedStyle(@element[0]).height
89
+ el.css('height', height)
90
+ el.css('line-height',height)
91
+ el.css('margin-top', '-' + height)
92
+ @element.bind 'dragleave', (event) =>
93
+ dragHovered -= 1
94
+ @element.removeClass('hovered') if dragHovered == 0
95
+ el.remove() if dragHovered == 0
96
+ @element.bind 'dragover', (event) =>
97
+ event.preventDefault()
98
+ event.stopPropagation()
99
+ @element.bind 'drop', (event) =>
100
+ event.preventDefault()
101
+ event.stopPropagation()
102
+ @element.removeClass('hovered')
103
+ el.remove()
104
+ dragHovered = 0
105
+ file = (event.originalEvent || event).dataTransfer.files[0]
106
+ @file_upload.uploadFile(file)
68
107
 
69
108
  angular.module('NgUpload', [])
70
109
 
71
- .directive 'ngDropFile', ->
110
+ .directive 'ngDropFile', ($timeout,$parse) ->
72
111
  restrict: 'A'
73
- require: 'ngModel'
74
- link: (scope, element, attributes) ->
75
- dragHovered = 0
76
- el = angular.element("<div class='hovered-cover'>Drop Files Here</div>")
77
- element.bind 'dragenter', (event) ->
78
- dragHovered += 1
79
- element.addClass('hovered') if dragHovered == 1
80
- element.append el if dragHovered == 1
81
- height = window.getComputedStyle(element[0]).height
82
- el.css('height', height)
83
- el.css('line-height',height)
84
- el.css('margin-top', '-' + height)
85
- element.bind 'dragleave', (event) ->
86
- dragHovered -= 1
87
- element.removeClass('hovered') if dragHovered == 0
88
- el.remove() if dragHovered == 0
89
- element.bind 'dragover', (event) ->
90
- event.preventDefault()
91
- event.stopPropagation()
92
- element.bind 'drop', (event) ->
93
- event.preventDefault()
94
- event.stopPropagation()
95
- element.removeClass('hovered')
96
- el.remove()
97
- dragHovered = 0
98
- file = (event.originalEvent || event).dataTransfer.files[0]
99
- selectFile(scope,event,attributes,file)
100
- scope.file = ->
101
- fileData(scope,attributes)
112
+ require: ['ngModel','?ngCallback']
113
+ link: (scope, element, attributes,controllers) ->
114
+ file_upload = new FileUpload($parse,scope,controllers,attributes.ngModel,attributes.ngOverride,element)
115
+ new NgDropFileEvents(element,file_upload)
116
+ scope.file_upload_data = -> file_upload.fileData()
102
117
 
103
- controller: ($scope, $element, $http, $timeout) ->
104
- callback = ->
105
- $element[0].attributes['ng-callback'].value if $element[0].attributes['ng-callback']
106
- $scope.uploadFiles = (model,id,file,parent) ->
107
- uploadFiles($scope,$element,model,id,file,parent,$timeout,callback())
108
- $scope.progress = 0
109
- $scope.uploadProgress = ->
110
- return $scope.progress
111
- .directive 'ngUpload', ->
118
+ .directive 'ngUpload', ($timeout, $parse) ->
112
119
  restrict: 'E'
113
120
  replace: true,
114
- require: 'ngModel',
121
+ require: ['ngModel','?ngCallback'],
115
122
  template:
116
- '<span class="ng-upload">
123
+ '<span class="ng-upload" style="outline: none">
117
124
  <div class="ng-progress-bar">
118
- <span class="bar" style="width: {{uploadProgress() || 0}}%;"></span><span class="text" style="margin-left: -{{uploadProgress() || 0}}%;">{{uploadProgress()}}%</span>
125
+ <span class="bar" style="width: {{progress || 0}}%;"></span><span class="text" style="margin-left: -{{uploadProgress() || 0}}%;">{{uploadProgress()}}%</span>
119
126
  </div>
120
- <input accept="{{accept()}}" ng-model="ngModel" type="file" ng-class="{image: show(&#39;image&#39;)}" /><img ng-show="show(&#39;image&#39;)" ng-src="{{file().thumb}}" />
121
- <div class="button" ng-show="show(&#39;button&#39;)">
127
+ <input accept="{{accept()}}" ng-model="ngModel" type="file" ng-class="{image: file_upload_show(&#39;image&#39;)}" /><img ng-show="file_upload_show(&#39;image&#39;)" ng-src="{{file_upload_data().thumb}}" />
128
+ <div class="button" ng-show="file_upload_show(&#39;button&#39;)">
122
129
  Select File
123
130
  </div>
124
- <a download="" href="{{file().path}}" ng-show="show(&#39;text&#39;)" target="_blank">{{file().name}}</a></span>'
131
+ <a download="" href="{{file_upload_data().path}}" ng-show="file_upload_show(&#39;text&#39;)" target="_blank">{{file_upload_data().name}}</a></span>'
125
132
 
126
- link: (scope, element, attributes) ->
127
- element.children('img').bind 'click', (event) ->
128
- this.parentElement.getElementsByTagName('input')[0].click()
129
- element.children('.button').bind 'click', (event) ->
130
- this.parentElement.getElementsByTagName('input')[0].click()
131
- element.children('input').bind 'click', (event) ->
132
- event.stopPropagation()
133
- element.children('input').bind 'change', (event) ->
134
- file = event.target.files[0]
135
- selectFile(scope,event,attributes,file)
136
- scope.file = ->
137
- fileData(scope,attributes)
138
- scope.accept = ->
139
- return attributes.accept if attributes.accept
140
- return '*'
141
- controller: ($scope, $element, $http, $timeout) ->
142
- callback = ->
143
- $element[0].attributes['ng-callback'].value if $element[0].attributes['ng-callback']
144
- $scope.show = (type) ->
145
- options = $element[0].attributes['ng-upload-options'].value.replace('{','').replace('}','').split(',')
146
- for option in options
147
- if option.indexOf(type) > -1
148
- return true if option.indexOf('true') > -1
149
- return false
150
- $scope.uploadFiles = (model,id,file,parent) ->
151
- uploadFiles($scope,$element,model,id,file,parent,$timeout,callback())
133
+ link: (scope, element, attributes,controllers) ->
134
+ file_upload = new FileUpload($parse,scope,controllers,attributes.ngModel,attributes.ngOverride,element)
135
+ new NgUploadEvents(element,file_upload)
136
+ options = $parse(attributes.ngUploadOptions)()
137
+ scope.file_upload_show = (type) -> options[type]
138
+ scope.file_upload_data = -> file_upload.fileData()
139
+ scope.accept = -> attributes.accept || '*'
@@ -1,3 +1,3 @@
1
1
  module MaterialRaingular
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
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.5
4
+ version: 0.0.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: 2016-03-28 00:00:00.000000000 Z
11
+ date: 2016-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler