material_raingular 0.2.8.6 → 0.3.0
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 +1 -0
- data/lib/assets/javascripts/directives/ngcreate.js.coffee +1 -0
- data/lib/assets/javascripts/directives/ngdrag.js.coffee +2 -0
- data/lib/assets/javascripts/directives/ngupdate.js.coffee +1 -0
- data/lib/assets/javascripts/material_raingular/directives/drop_file/directive.coffee +4 -0
- data/lib/assets/javascripts/material_raingular/directives/drop_file/drop_events.coffee +27 -0
- data/lib/assets/javascripts/material_raingular/directives/drop_file/linkmodel.coffee +17 -0
- data/lib/assets/javascripts/material_raingular/directives/upload/directive.coffee +17 -0
- data/lib/assets/javascripts/material_raingular/directives/upload/events.coffee +10 -0
- data/lib/assets/javascripts/material_raingular/directives/upload/linkmodel.coffee +37 -0
- data/lib/assets/javascripts/material_raingular/helpers/file_upload.coffee +42 -0
- data/lib/assets/javascripts/material_raingular/helpers/ng_model_parse.coffee +6 -0
- data/lib/assets/javascripts/super_classes/angular_compile_model.coffee +8 -3
- data/lib/material_raingular/version.rb +1 -1
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e849b4413ab5d0ea74e9c93be9f0ccd3bcde92ef
|
4
|
+
data.tar.gz: 01ff63bf054c3930763065ff3cb4ba29206ea11d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae8490d5e48a5489ec0184835d9846702c0d51477d3e65d6d2990d331c28ccac98cbe194c6b5ba14bbff5106c0a3927119a977ffa23616971e78c05eadfa8a18
|
7
|
+
data.tar.gz: 871dd25b4ba62558de880b53b09010a02711a608aac3e8dd29a5f33a3cd10dd0fa201997150139ea6e6f054dc774a2f6db5f8dcd2c43fded4e0e663796fb6ea6
|
@@ -57,4 +57,5 @@ angular.module 'MdUpdate', ['Factories', 'FactoryName','RailsUpdater']
|
|
57
57
|
require: ['ngModel','?ngCallback','?ngTrackBy']
|
58
58
|
|
59
59
|
link: (scope, element, attributes, ngControllers) ->
|
60
|
+
console.warn 'mdUpdate is deprecated. Please consider using mrUpdate in its stead.'
|
60
61
|
new ElementUpdate(scope,element,attributes,ngControllers, RailsUpdater,$timeout,$parse)
|
@@ -4,6 +4,7 @@ angular.module 'NgCreate', ['Factories', 'FactoryName']
|
|
4
4
|
restrict: 'A'
|
5
5
|
require: '?ngCallback'
|
6
6
|
link: (scope, element, attributes, ngCallbackCtrl) ->
|
7
|
+
console.warn 'ngCreate is deprecated. Please consider using mrCreate in its stead.'
|
7
8
|
element.bind 'click', (event) ->
|
8
9
|
[parentName, listName] = attributes.ngContext.split('.') if attributes.ngContext
|
9
10
|
attr = scope.$eval('(' + attributes.ngAttributes + ')') || {}
|
@@ -80,6 +80,7 @@ angular.module('NgDrag', [])
|
|
80
80
|
|
81
81
|
.directive 'ngDrag', ->
|
82
82
|
link: (scope, element, attributes, ngModelCtrl) ->
|
83
|
+
console.warn 'ngDrag is deprecated. Please consider using mrDrag in its stead.'
|
83
84
|
callFunction = attributes.ngDrag
|
84
85
|
el = element[0]
|
85
86
|
el.draggable = true
|
@@ -92,6 +93,7 @@ angular.module('NgDrag', [])
|
|
92
93
|
|
93
94
|
.directive 'ngDrop', ->
|
94
95
|
link: (scope, element, attributes, ngModelCtrl) ->
|
96
|
+
console.warn 'ngDrop is deprecated. Please consider using mrDrop in its stead.'
|
95
97
|
callFunction = attributes.ngDrop
|
96
98
|
el = element[0]
|
97
99
|
el.droppable = true
|
@@ -5,6 +5,7 @@ angular.module 'NgUpdate', ['Factories', 'FactoryName']
|
|
5
5
|
require: '?ngCallback'
|
6
6
|
|
7
7
|
link: (scope, element, attributes, ngCallbackCtrl) ->
|
8
|
+
console.warn 'ngUpdate is deprecated. Please consider using mrUpdate in its stead.'
|
8
9
|
model = attributes.ngUpdate.split('"').join('\'')
|
9
10
|
html = element[0].outerHTML
|
10
11
|
html = angular.element(html)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Modules.MrDropFileEvents
|
2
|
+
constructor: (@element,@fileUpload) ->
|
3
|
+
dragHovered = 0
|
4
|
+
el = angular.element("<div class='hovered-cover'>Drop Files Here</div>")
|
5
|
+
@element.bind 'dragenter', (event) =>
|
6
|
+
dragHovered += 1
|
7
|
+
@element.addClass('hovered') if dragHovered == 1
|
8
|
+
@element.append el if dragHovered == 1
|
9
|
+
height = window.getComputedStyle(@element[0]).height
|
10
|
+
el.css('height', height)
|
11
|
+
el.css('line-height',height)
|
12
|
+
el.css('margin-top', '-' + height)
|
13
|
+
@element.bind 'dragleave', (event) =>
|
14
|
+
dragHovered -= 1
|
15
|
+
@element.removeClass('hovered') if dragHovered == 0
|
16
|
+
el.remove() if dragHovered == 0
|
17
|
+
@element.bind 'dragover', (event) =>
|
18
|
+
event.preventDefault()
|
19
|
+
event.stopPropagation()
|
20
|
+
@element.bind 'drop', (event) =>
|
21
|
+
event.preventDefault()
|
22
|
+
event.stopPropagation()
|
23
|
+
@element.removeClass('hovered')
|
24
|
+
el.remove()
|
25
|
+
dragHovered = 0
|
26
|
+
file = (event.originalEvent || event).dataTransfer.files[0]
|
27
|
+
@fileUpload.uploadFile(file)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# //= require material_raingular/directives/drop_file/drop_events
|
2
|
+
class DirectiveModels.MrDropFileModel extends AngularLinkModel
|
3
|
+
initialize: ->
|
4
|
+
[@ngModelCtrl,@mrCallbackCtrl] = @$controller
|
5
|
+
[@model,@key] = Helpers.NgModelParse(@$attrs.ngModel,@$scope)
|
6
|
+
@fileUpload = new Helpers.FileUpload(@$scope,@model,@key,@$element,@callback)
|
7
|
+
new Modules.MrDropFileEvents(@$element,@fileUpload)
|
8
|
+
|
9
|
+
callback: (data) =>
|
10
|
+
@$scope.$apply =>
|
11
|
+
@$scope[@model][@key] = data[@key]
|
12
|
+
@$scope[@model].thumb = data.thumb
|
13
|
+
@$scope[@model].id = data.id unless @$scope[@model].id
|
14
|
+
@$scope.progress = 100
|
15
|
+
@$element.removeClass('covered')
|
16
|
+
@mrCallbackCtrl?.evaluate(data)
|
17
|
+
@register(Directives.MrDropFile)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Directives.MrUpload extends AngularDirective
|
2
|
+
restrict: 'E'
|
3
|
+
replace: true
|
4
|
+
require: ['ngModel','?mrCallback']
|
5
|
+
template: (element,attributes) ->
|
6
|
+
disabled = typeof(attributes.disabled) != 'undefined'
|
7
|
+
'<span class="mr-upload" style="outline: none">
|
8
|
+
<div class="mr-progress-bar">
|
9
|
+
<span class="bar" style="width: {{progress || 0}}%;"></span><span class="text" style="margin-left: -{{uploadProgress() || 0}}%;">{{uploadProgress()}}%</span>
|
10
|
+
</div>
|
11
|
+
<input accept="{{accept()}}" ng-model="ngModel" type="file" ng-class="{image: fileUploadShow(\'image\')}" ' + (if disabled then 'disabled ' else '') + '/>
|
12
|
+
<img ng-show="fileUploadShow(\'image\')" ng-src="{{fileData().thumb}}" />
|
13
|
+
<div class="button" ng-show="fileUploadShow(\'button\')">
|
14
|
+
Select File
|
15
|
+
</div>
|
16
|
+
<a download="" href="{{fileData().path}}" ng-show="fileUploadShow(\'text\')" target="_blank">{{fileData().name}}</a></span>'
|
17
|
+
@register(MaterialRaingular.app)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class Modules.MrUploadEvents
|
2
|
+
constructor: (@element,@fileUpload,@disabled) ->
|
3
|
+
@element.children().bind 'click', (event) =>
|
4
|
+
return if @disabled()
|
5
|
+
return if event.target.tagName == 'A'
|
6
|
+
event.target.parentElement.getElementsByTagName('input')[0].click()
|
7
|
+
@element.children('input').bind 'change', (event) =>
|
8
|
+
return if @disabled()
|
9
|
+
file = event.target.files[0]
|
10
|
+
@fileUpload.uploadFile(file)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# //= require_tree ../../helpers
|
2
|
+
# //= require material_raingular/directives/upload/events
|
3
|
+
class DirectiveModels.MrUploadModel extends AngularLinkModel
|
4
|
+
@inject(
|
5
|
+
'$timeout'
|
6
|
+
'RailsUpdater'
|
7
|
+
)
|
8
|
+
initialize: ->
|
9
|
+
[@ngModelCtrl,@mrCallbackCtrl] = @$controller
|
10
|
+
[@model,@key] = Helpers.NgModelParse(@$attrs.ngModel,@$scope)
|
11
|
+
@fileUpload = new Helpers.FileUpload(@$scope,@model,@key,@$element,@callback)
|
12
|
+
@options = @$scope.$eval(@$attrs.mrUploadOptions)
|
13
|
+
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)
|
22
|
+
|
23
|
+
fileData: ->
|
24
|
+
data = {}
|
25
|
+
data.path = @$scope[@model]?[@key]?.url
|
26
|
+
data.name = @$scope[@model]?[@key]?.name
|
27
|
+
data.thumb = @$scope[@model]?.thumb?.url
|
28
|
+
return data
|
29
|
+
fileUploadShow: (type) -> @options[type]
|
30
|
+
disabled: =>
|
31
|
+
el = @$element[0]
|
32
|
+
until !el.parentElement
|
33
|
+
return true if el.getAttribute('disabled')
|
34
|
+
el = el.parentElement
|
35
|
+
accept: -> @$attrs.accept || '*'
|
36
|
+
|
37
|
+
@register(Directives.MrUpload)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
@Helpers ?= {}
|
2
|
+
class Helpers.FileUpload
|
3
|
+
constructor: (@scope,@modelName,@key,@element,@callback)->
|
4
|
+
uploadFile: (file)->
|
5
|
+
@scope.progress = 0
|
6
|
+
@element.addClass('covered')
|
7
|
+
if id = @scope.$eval(@modelName).id
|
8
|
+
route = Routes[@modelName + '_path'](id: id) + '.json'
|
9
|
+
method = 'PUT'
|
10
|
+
else
|
11
|
+
route = Routes[@modelName.pluralize() + '_path']() + '.json'
|
12
|
+
method = 'POST'
|
13
|
+
formData = new FormData()
|
14
|
+
formData.append @modelName + '[id]', id if id
|
15
|
+
formData.append @modelName + '[' + @key + ']', file
|
16
|
+
xhr = new XMLHttpRequest()
|
17
|
+
xhr.upload.addEventListener "progress", (event) =>
|
18
|
+
if event.lengthComputable
|
19
|
+
@scope.$apply =>
|
20
|
+
@scope.progress = Math.round(event.loaded * 100 / event.total)
|
21
|
+
, 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
|
30
|
+
xhr.open(method, route)
|
31
|
+
csrf = null
|
32
|
+
for tag in document.getElementsByTagName('meta')
|
33
|
+
csrf = tag.content if tag.name == 'csrf-token'
|
34
|
+
xhr.setRequestHeader('X-CSRF-Token', csrf)
|
35
|
+
xhr.send(formData)
|
36
|
+
@failed: (event)=>
|
37
|
+
@element.addClass('failed')
|
38
|
+
|
39
|
+
timeout ->
|
40
|
+
@element.removeClass('failed')
|
41
|
+
@element.removeClass('covered')
|
42
|
+
, 2000
|
@@ -1,13 +1,18 @@
|
|
1
|
-
# //= require super_classes/
|
1
|
+
# //= require super_classes/angular_scoped_model
|
2
2
|
class @AngularCompileModel extends AngularModel
|
3
3
|
@register: (model,type) -> model::[type || 'compile'] = (args...) => new @(args...)
|
4
4
|
@$default_arguments: ['element','attrs','transcludeFn']
|
5
5
|
constructor: (args...) ->
|
6
|
-
for key,index in @constructor.$default_arguments
|
7
|
-
@['$' + key] = args[index]
|
8
6
|
@$injector = angular.element(document.body).injector()
|
9
7
|
for key in @constructor.$inject || []
|
10
8
|
@[key] = @$injector.get(key)
|
9
|
+
for key,index in @constructor.$default_arguments
|
10
|
+
@['$' + key] = args[index]
|
11
|
+
# Bind all functions not begining with _ to scope
|
12
|
+
for key, val of @constructor.prototype
|
13
|
+
continue if key in ['constructor', 'initialize'] or key[0] is '_'
|
14
|
+
@$scope[key] = if (typeof val is 'function') then val.bind?(@) || _.bind(val, @) else val
|
15
|
+
|
11
16
|
@initialize?()
|
12
17
|
###
|
13
18
|
class CompileModel extends AngularLinkModel
|
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.
|
4
|
+
version: 0.3.0
|
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-01-
|
11
|
+
date: 2017-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -113,8 +113,16 @@ files:
|
|
113
113
|
- lib/assets/javascripts/material_raingular/directives/drag/linkmodel.coffee
|
114
114
|
- lib/assets/javascripts/material_raingular/directives/drop/directive.coffee
|
115
115
|
- lib/assets/javascripts/material_raingular/directives/drop/linkmodel.coffee
|
116
|
+
- lib/assets/javascripts/material_raingular/directives/drop_file/directive.coffee
|
117
|
+
- lib/assets/javascripts/material_raingular/directives/drop_file/drop_events.coffee
|
118
|
+
- lib/assets/javascripts/material_raingular/directives/drop_file/linkmodel.coffee
|
116
119
|
- lib/assets/javascripts/material_raingular/directives/update/directive.coffee
|
117
120
|
- lib/assets/javascripts/material_raingular/directives/update/linkmodel.coffee
|
121
|
+
- lib/assets/javascripts/material_raingular/directives/upload/directive.coffee
|
122
|
+
- lib/assets/javascripts/material_raingular/directives/upload/events.coffee
|
123
|
+
- lib/assets/javascripts/material_raingular/directives/upload/linkmodel.coffee
|
124
|
+
- lib/assets/javascripts/material_raingular/helpers/file_upload.coffee
|
125
|
+
- lib/assets/javascripts/material_raingular/helpers/ng_model_parse.coffee
|
118
126
|
- lib/assets/javascripts/rails_updater.coffee
|
119
127
|
- lib/assets/javascripts/super_classes/angular_compile_model.coffee
|
120
128
|
- lib/assets/javascripts/super_classes/angular_directive.coffee
|