material_raingular 0.6.1.1 → 0.6.2

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: 155bb1da6fc4893669b1cf77beb11335a210d334
4
- data.tar.gz: 9891f2bb6516cf51b0af570ef13f4e1d2745251f
3
+ metadata.gz: 048dd75a86b0e3786218da9a1206216838e8b692
4
+ data.tar.gz: 4efe491a8fdeee8c09c1d6bbd4e8ed7ad8f0d9df
5
5
  SHA512:
6
- metadata.gz: 02d485368f2175c6058da01633deb5ec20f2837cb6f7dddbacc8d354e5c4a5b9a24778bee3680c74a2f0c8de55b4075f5ede1bb4a715cd46ccf088d6a9f80efb
7
- data.tar.gz: e8a5966065a4d8114006ea795cd355654191804566fbe71ccb27664053abf5a1415e2357f35ba6b24b2e0e762a8f41f9aac6cef1ac509255b007dc51abe1d909
6
+ metadata.gz: 6a5a3a333fc5f092cb7d518acb617513216d141b906d95c32eab2ce17bba6d549cee69cbc745c164358d2e1fbb5ba433f2ad494f1e1fdd44f7082f4d479940ff
7
+ data.tar.gz: 5fed44633b7fa405ee270e96b98ee3cb93a29da6073c57ed7ab4e842e7d6d352b80b7c503f5f579a0b361e2b6a8d345aca66ae95b27c83c811cce1ab192dccdf
@@ -1,9 +1,10 @@
1
1
  # //= require material_raingular/directives/drop_file/drop_events
2
2
  class DirectiveModels.MrDropFileModel extends AngularLinkModel
3
+ @inject('$injector')
3
4
  initialize: ->
4
5
  [@ngModelCtrl,@mrCallbackCtrl] = @$controller
5
6
  [@model,@key] = Helpers.NgModelParse(@$attrs.ngModel,@$scope)
6
- @fileUpload = new Helpers.FileUpload(@$scope,@model,@key,@$element,@callback)
7
+ @fileUpload = new Helpers.FileUpload(@$scope,@model,@key,@$element,@callback,@$injector)
7
8
  new Modules.MrDropFileEvents(@$element,@fileUpload)
8
9
 
9
10
  callback: (data) =>
@@ -2,23 +2,21 @@
2
2
  # //= require material_raingular/directives/upload/events
3
3
  class DirectiveModels.MrUploadModel extends AngularLinkModel
4
4
  @inject(
5
- '$timeout'
6
- 'RailsUpdater'
5
+ '$injector'
7
6
  )
8
7
  initialize: ->
9
8
  [@ngModelCtrl,@mrCallbackCtrl] = @$controller
10
9
  [@model,@key] = Helpers.NgModelParse(@$attrs.ngModel,@$scope)
11
- @fileUpload = new Helpers.FileUpload(@$scope,@model,@key,@$element,@callback)
10
+ @fileUpload = new Helpers.FileUpload(@$scope,@model,@key,@$element,@callback.bind(@),@$injector)
12
11
  @options = @$scope.$eval(@$attrs.mrUploadOptions)
13
12
  new Modules.MrUploadEvents(@$element,@fileUpload,@disabled)
14
- callback: (data) =>
15
- @$scope.$apply =>
16
- @$scope[@model][@key] = data[@key]
17
- @$scope[@model].thumb = data.thumb
18
- @$scope[@model].id = data.id unless @$scope[@model].id
19
- @$scope.progress = 100
20
- @$element.removeClass('covered')
21
- @mrCallbackCtrl?.evaluate(data)
13
+ callback: (data) ->
14
+ @$scope[@model][@key] = data[@key]
15
+ @$scope[@model].thumb = data.thumb
16
+ @$scope[@model].id = data.id unless @$scope[@model].id
17
+ @$scope.progress = 100
18
+ @$element.removeClass('covered')
19
+ @mrCallbackCtrl?.evaluate(data)
22
20
 
23
21
  fileData: ->
24
22
  data = {}
@@ -1,10 +1,14 @@
1
1
  @Helpers ?= {}
2
2
  class Helpers.FileUpload
3
- constructor: (@scope,@modelName,@key,@element,@callback)->
3
+ constructor: (@scope,@modelName,@key,@element,@callback,@$injector)->
4
+ @$timeout = @$injector.get '$timeout'
5
+ @$q = @$injector.get '$q'
6
+ @model = @scope.$eval(@modelName)
7
+ ActiveRecord.$Resource._resourcify(@model,@modelName.classify())
4
8
  uploadFile: (file)->
5
9
  @scope.progress = 0
6
10
  @element.addClass('covered')
7
- if id = @scope.$eval(@modelName).id
11
+ if id = @model.id
8
12
  route = Routes[@modelName + '_path'](id: id) + '.json'
9
13
  method = 'PUT'
10
14
  else
@@ -15,28 +19,31 @@ class Helpers.FileUpload
15
19
  formData.append @modelName + '[' + @key + ']', file
16
20
  xhr = new XMLHttpRequest()
17
21
  xhr.upload.addEventListener "progress", (event) =>
18
- if event.lengthComputable
19
- @scope.$apply =>
20
- @scope.progress = Math.round(event.loaded * 100 / event.total)
22
+ return unless event.lengthComputable
23
+ @scope.$apply =>
24
+ @scope.progress = Math.round(event.loaded * 100 / event.total)
21
25
  , true
22
- xhr.addEventListener "readystatechange", (event) =>
23
- if event.target.readyState == 4 && !(event.target.status > 399)
24
- data = JSON.parse(event.target.response)
25
- @callback(data)
26
- else if event.target.readyState == 4 && event.target.status > 399
27
- @failed()
28
- , false
29
- xhr.addEventListener "error", @failed, false
26
+ xhr.addEventListener "error", @failed.bind(@), false
30
27
  xhr.open(method, route)
31
28
  csrf = null
32
29
  for tag in document.getElementsByTagName('meta')
33
30
  csrf = tag.content if tag.name == 'csrf-token'
34
31
  xhr.setRequestHeader('X-CSRF-Token', csrf)
35
- xhr.send(formData)
36
- @failed: (event)=>
32
+ promise = ->
33
+ @$q (resolve,reject) ->
34
+ xhr.onreadystatechange = ->
35
+ return unless xhr.readyState == 4
36
+ if xhr.status == 200
37
+ resolve(JSON.parse xhr.responseText)
38
+ else
39
+ reject(JSON.parse xhr.responseText)
40
+ xhr.send(formData)
41
+ @model.$promise = @model.$promise.then(promise.bind(@)).then(@success.bind(@),@failed.bind(@))
42
+ @model.$promise.then(@model.$save.bind(@model))
43
+ success: (data) -> @callback(data)
44
+ failed: (data) ->
37
45
  @element.addClass('failed')
38
-
39
- timeout ->
46
+ @$timeout =>
40
47
  @element.removeClass('failed')
41
48
  @element.removeClass('covered')
42
49
  , 2000
@@ -1,3 +1,3 @@
1
1
  module MaterialRaingular
2
- VERSION = "0.6.1.1"
2
+ VERSION = "0.6.2"
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.6.1.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Moody
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-16 00:00:00.000000000 Z
11
+ date: 2017-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler