abstracted 0.2.2 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/abstract_resources.js +5 -1
- data/app/assets/javascripts/abstracted/app.fab_delete.coffee +161 -0
- data/app/assets/javascripts/abstracted/app.materialize.coffee +32 -0
- data/app/assets/javascripts/abstracted/app.resource_form.coffee +59 -0
- data/app/assets/javascripts/abstracted/app.resources_list.coffee +239 -0
- data/app/assets/javascripts/abstracted/app.shared.coffee +125 -0
- data/app/assets/javascripts/abstracted/app.sweetalert.coffee +32 -0
- data/app/assets/javascripts/abstracted/keypress.coffee +23 -0
- data/app/assets/javascripts/init.js.coffee +22 -10
- data/app/assets/javascripts/triggers.coffee +34 -0
- data/lib/abstracted/version.rb +1 -1
- metadata +10 -4
- data/app/assets/javascripts/crud.js.coffee +0 -194
- data/app/assets/javascripts/initializers.js.coffee +0 -457
@@ -1,457 +0,0 @@
|
|
1
|
-
# this var holds whatever HTML has been parked
|
2
|
-
# to make room for a loader
|
3
|
-
#
|
4
|
-
|
5
|
-
# cloneObject will make a copy of an object - not a copy of the reference
|
6
|
-
# to some object!
|
7
|
-
#
|
8
|
-
# var obj1= {bla:'blabla',foo:'foofoo',etc:'etc'};
|
9
|
-
# var obj2= new cloneObject(obj1);
|
10
|
-
#
|
11
|
-
# 03-07-2015 (whd) not sure whether this method is OK!!!!
|
12
|
-
# cp'ed from: http://scriptcult.com/subcategory_1/article_414-copy-or-clone-javascript-array-object
|
13
|
-
#
|
14
|
-
@cloneObject = (source) ->
|
15
|
-
for i in source
|
16
|
-
if typeof source[i] == 'source'
|
17
|
-
this[i] = new cloneObject source[i]
|
18
|
-
else
|
19
|
-
this[i] = source[i]
|
20
|
-
|
21
|
-
|
22
|
-
# it will be re-instated with releaseLoader
|
23
|
-
loaded_html = ""
|
24
|
-
loaded_element = ""
|
25
|
-
|
26
|
-
#
|
27
|
-
# set a loader - see http://materializecss.com/preloader.html
|
28
|
-
# for examples
|
29
|
-
#
|
30
|
-
@setLoader = (elem,html) ->
|
31
|
-
html ||= '<div class="progress"><div class="indeterminate"></div></div>'
|
32
|
-
loaded_element = $(elem)
|
33
|
-
loaded_html = elem.html()
|
34
|
-
elem.html(html)
|
35
|
-
|
36
|
-
#
|
37
|
-
# release the loader
|
38
|
-
#
|
39
|
-
@releaseLoader = (elem=null) ->
|
40
|
-
elem ||= loaded_element
|
41
|
-
$(elem).html(loaded_html)
|
42
|
-
|
43
|
-
#
|
44
|
-
# make sure fields with values do not have their labels obscuring your view
|
45
|
-
#
|
46
|
-
@setLabels = (selector) ->
|
47
|
-
$(selector).each () ->
|
48
|
-
try
|
49
|
-
fld = '#'+$(this).attr('for')
|
50
|
-
$(this).addClass('active') unless $(fld)[0].value.nil?
|
51
|
-
catch
|
52
|
-
#console.log this
|
53
|
-
|
54
|
-
|
55
|
-
@tellResponse = (msg,anchor='.message_container',fade=15000,selector='.alert') ->
|
56
|
-
$(anchor).prepend(msg)
|
57
|
-
if fade>0
|
58
|
-
fadeItOut $(anchor).find(selector), 15000
|
59
|
-
|
60
|
-
@reportError = (msg) ->
|
61
|
-
Materialize.toast( msg, 4500, 'red lighten-3')
|
62
|
-
|
63
|
-
@closeSweetAlert = ($elem=null) ->
|
64
|
-
try
|
65
|
-
unless $elem == undefined
|
66
|
-
$elem.show()
|
67
|
-
swal.close()
|
68
|
-
catch error
|
69
|
-
$('.sweet-overlay').hide()
|
70
|
-
$('.sweet-alert').hide()
|
71
|
-
|
72
|
-
|
73
|
-
#
|
74
|
-
# initializeSweetAlert
|
75
|
-
# initializes the sweetalert prompt
|
76
|
-
#
|
77
|
-
@initializeSweetAlert = () ->
|
78
|
-
try
|
79
|
-
# console.log 'sweet alert initializing...'
|
80
|
-
# sweetHTML = '<div class="sweet-overlay" tabIndex="-1"></div><div class="sweet-alert" tabIndex="-1"><div class="icon error"><span class="x-mark"><span class="line left"></span><span class="line right"></span></span></div><div class="icon warning"> <span class="body"></span> <span class="dot"></span> </div> <div class="icon info"></div> <div class="icon success"> <span class="line tip"></span> <span class="line long"></span> <div class="placeholder"></div> <div class="fix"></div> </div> <div class="icon custom"></div> <h2>Title</h2><p>Text</p><button class="cancel" tabIndex="2">Cancel</button><button class="confirm" tabIndex="1">OK</button></div>'
|
81
|
-
# sweetWrap = document.createElement('div')
|
82
|
-
# sweetWrap.innerHTML = sweetHTML
|
83
|
-
# $(document.body).append(sweetWrap)
|
84
|
-
# console.log 'sweetalert initialized!'
|
85
|
-
catch error
|
86
|
-
console.log 'sweetalert says: ' + error
|
87
|
-
|
88
|
-
#
|
89
|
-
# handleAttachLinks
|
90
|
-
# allows for attaching/detaching resources from their parents - like: /admin/users/2/printers/3/attach.js
|
91
|
-
#
|
92
|
-
@handleAttachLinks = (e) ->
|
93
|
-
e.preventDefault()
|
94
|
-
e.stopPropagation()
|
95
|
-
|
96
|
-
$elem = $(e.currentTarget)
|
97
|
-
request = $.ajax
|
98
|
-
url: $elem.attr('href'),
|
99
|
-
type: "get",
|
100
|
-
dataType: 'html'
|
101
|
-
.done (data) ->
|
102
|
-
$( $elem[0].parentElement).html(data)
|
103
|
-
|
104
|
-
.error (data) ->
|
105
|
-
swal("Oops", "We couldn't connect to the server!", "error")
|
106
|
-
return false
|
107
|
-
|
108
|
-
#
|
109
|
-
# handleActivateLinks
|
110
|
-
# allows for activating/deactivating resources - like: /admin/users/2/activate
|
111
|
-
#
|
112
|
-
@handleActivateLinks = (e) ->
|
113
|
-
e.preventDefault()
|
114
|
-
e.stopPropagation()
|
115
|
-
|
116
|
-
$elem = $(e.currentTarget)
|
117
|
-
request = $.ajax
|
118
|
-
url: $elem.attr('href'),
|
119
|
-
type: "get",
|
120
|
-
dataType: 'html'
|
121
|
-
.done (data) ->
|
122
|
-
$( $elem[0].parentElement).html(data)
|
123
|
-
|
124
|
-
.error (data) ->
|
125
|
-
swal("Oops", "We couldn't connect to the server!", "error")
|
126
|
-
return false
|
127
|
-
|
128
|
-
|
129
|
-
#
|
130
|
-
# handlePreferredLinks
|
131
|
-
# allows for activating/deactivating resources - like: /admin/users/2/activate
|
132
|
-
#
|
133
|
-
@handlePreferredLinks = (e) ->
|
134
|
-
e.preventDefault()
|
135
|
-
e.stopPropagation()
|
136
|
-
|
137
|
-
$elem = $(e.currentTarget)
|
138
|
-
request = $.ajax
|
139
|
-
url: $elem.attr('href'),
|
140
|
-
type: "get",
|
141
|
-
dataType: 'html'
|
142
|
-
.done (data) ->
|
143
|
-
# here we have to write all the existing preferred ones
|
144
|
-
$.when $('i.preferred').each (k,e) ->
|
145
|
-
$e = $(e)
|
146
|
-
$( $e[0].parentElement).html( data.replace /{{id}}/, $e.data('id'))
|
147
|
-
# $( $elem[0].parentElement).html(data)
|
148
|
-
.then $( $elem[0].parentElement).html('<i class="preferred material-icons green-text" data-id="' + $elem.data('id') + '">bookmark</i>')
|
149
|
-
|
150
|
-
.error (data) ->
|
151
|
-
swal("Oops", "We couldn't connect to the server!", "error")
|
152
|
-
return false
|
153
|
-
|
154
|
-
#
|
155
|
-
# handlePrintLinks
|
156
|
-
# initializes the tags classed with '.print_post_link' to print a post
|
157
|
-
#
|
158
|
-
@handlePrintLinks = (e) ->
|
159
|
-
e.preventDefault()
|
160
|
-
e.stopPropagation()
|
161
|
-
|
162
|
-
$elem = $(e.currentTarget)
|
163
|
-
loader = '<div class="preloader-wrapper small active"> <div class="spinner-layer spinner-blue-only"> <div class="circle-clipper left"> <div class="circle"></div> </div><div class="gap-patch"> <div class="circle"></div> </div><div class="circle-clipper right"> <div class="circle"></div> </div> </div> </div>'
|
164
|
-
loaded_element = $elem.closest('.loader_container')
|
165
|
-
setLoader( loaded_element,loader )
|
166
|
-
printPost($elem)
|
167
|
-
return false
|
168
|
-
|
169
|
-
#
|
170
|
-
# handleDeleteLinks
|
171
|
-
# initializes the tags classed with '.delete_link' to verify deleting an issue
|
172
|
-
#
|
173
|
-
@handleDeleteLinks = (e) ->
|
174
|
-
e.preventDefault()
|
175
|
-
e.stopPropagation()
|
176
|
-
$elem = $(e.currentTarget)
|
177
|
-
$elem.hide()
|
178
|
-
|
179
|
-
$('.sweet-overlay').show()
|
180
|
-
swal
|
181
|
-
title: "Are you sure?",
|
182
|
-
text: "Are you sure that you want to delete this photo?",
|
183
|
-
type: "warning",
|
184
|
-
animation: "slide-from-bottom",
|
185
|
-
showLoaderOnConfirm: true,
|
186
|
-
showCancelButton: true,
|
187
|
-
closeOnConfirm: false,
|
188
|
-
confirmButtonText: "Yes, delete it!",
|
189
|
-
confirmButtonColor: "#ec6c62",
|
190
|
-
(confirmed) ->
|
191
|
-
if !confirmed
|
192
|
-
closeSweetAlert($elem)
|
193
|
-
else
|
194
|
-
deletePost($elem)
|
195
|
-
return false
|
196
|
-
|
197
|
-
#
|
198
|
-
# starting a search - and making some noise about it!
|
199
|
-
#
|
200
|
-
@searchKey = (e) ->
|
201
|
-
if e.keyCode == 13
|
202
|
-
e.preventDefault()
|
203
|
-
e.stopPropagation()
|
204
|
-
$elem = $('input.search-list')
|
205
|
-
orderSearch(inputForm.action, $elem.val())
|
206
|
-
|
207
|
-
#
|
208
|
-
# starting a search - and making some noise about it!
|
209
|
-
#
|
210
|
-
@searchClick = (e) ->
|
211
|
-
e.preventDefault()
|
212
|
-
e.stopPropagation()
|
213
|
-
$elem = $('input.search-list')
|
214
|
-
orderSearch(inputForm.action, $elem.val())
|
215
|
-
|
216
|
-
|
217
|
-
inputForm = null
|
218
|
-
#
|
219
|
-
# initializeForm
|
220
|
-
# on pages with a FORM element - like show, new and edit
|
221
|
-
# prepare the FORM element
|
222
|
-
#
|
223
|
-
@initializeForm = (f) ->
|
224
|
-
inputForm = f
|
225
|
-
#
|
226
|
-
# Initialize SELECT's
|
227
|
-
#
|
228
|
-
$('select').each () ->
|
229
|
-
# remove span.caret's from previous 'runs' - however that happens
|
230
|
-
$(this).parent().parent().find('span.caret').remove()
|
231
|
-
$(this).material_select()
|
232
|
-
|
233
|
-
#
|
234
|
-
# make labels on fields with content move out of the way
|
235
|
-
#
|
236
|
-
setLabels('.input-field label')
|
237
|
-
|
238
|
-
$(document.body).on 'keydown.search', 'input.search-list', searchKey
|
239
|
-
$(document.body).on 'click.search', 'form a.search-list[type="submit"]', searchClick
|
240
|
-
|
241
|
-
#
|
242
|
-
# Initialize INPUT TYPE='DATE'
|
243
|
-
#
|
244
|
-
# %input.datepicker{ type:"date" }
|
245
|
-
#
|
246
|
-
$('.datepicker').pickadate
|
247
|
-
selectMonths: true, # Creates a dropdown to control month
|
248
|
-
selectYears: 15 # Creates a dropdown of 15 years to control year
|
249
|
-
|
250
|
-
#
|
251
|
-
# setup a dropbox file upload
|
252
|
-
#
|
253
|
-
@prepareUpload = (e) ->
|
254
|
-
if $('.dropbox').size() > 0
|
255
|
-
a=1
|
256
|
-
#medium = new Medium()
|
257
|
-
#medium.initializeBindings()
|
258
|
-
|
259
|
-
|
260
|
-
#
|
261
|
-
# handleFABLinks
|
262
|
-
# handles click on the fab_button
|
263
|
-
#
|
264
|
-
@handleFABLinks = (e) ->
|
265
|
-
e.preventDefault()
|
266
|
-
e.stopPropagation()
|
267
|
-
elem = $(e.currentTarget)
|
268
|
-
if elem.data('browser')=='new'
|
269
|
-
window.open elem.data('url')
|
270
|
-
return
|
271
|
-
|
272
|
-
loader = '<div class="preloader-wrapper medium active"> <div class="spinner-layer spinner-blue-only"> <div class="circle-clipper left"> <div class="circle"></div> </div><div class="gap-patch"> <div class="circle"></div> </div><div class="circle-clipper right"> <div class="circle"></div> </div> </div> </div>'
|
273
|
-
setLoader( $(elem).closest('.fixed-action-btn'),loader)
|
274
|
-
oxremote = elem.data('oxremote')
|
275
|
-
if (oxremote=='false' or oxremote==false)
|
276
|
-
switch elem.data('method')
|
277
|
-
when 'post', 'POST'
|
278
|
-
# elem.closest('form').submit()
|
279
|
-
$('form').submit()
|
280
|
-
when 'put', 'PUT'
|
281
|
-
console.log 'how do I put? add code in abstracted/app/assets/javascripts/initializers.js.coffee'
|
282
|
-
when 'get', 'GET'
|
283
|
-
window.location.href = elem.data('url')
|
284
|
-
else
|
285
|
-
jqxhr = $.ajax
|
286
|
-
url: elem.data('url') || elem.attr('href')
|
287
|
-
type: elem.data('method') || 'get'
|
288
|
-
data: dataArgumentOn(elem)
|
289
|
-
dataType: elem.data('type') || 'html'
|
290
|
-
.done (data) ->
|
291
|
-
releaseLoader()
|
292
|
-
if elem.data('modal')
|
293
|
-
$(elem.data('modal')).html(data).openModal()
|
294
|
-
else
|
295
|
-
$(document.body).append(data)
|
296
|
-
.error (data) ->
|
297
|
-
releaseLoader()
|
298
|
-
$(document.body).append(data)
|
299
|
-
return false
|
300
|
-
|
301
|
-
#
|
302
|
-
# fadeItOut will fade an element out with a preset or
|
303
|
-
# supplied delay
|
304
|
-
#
|
305
|
-
@fadeItOut = (e,delay=3500) ->
|
306
|
-
$(e).delay( delay ).fadeOut( 1000 )
|
307
|
-
|
308
|
-
#
|
309
|
-
# dataArgumentOn constructs the data: argument on AJAX calls
|
310
|
-
# from what ever data- attributes an element holds
|
311
|
-
#
|
312
|
-
# excemptions: data-id, data-remote, data-ajax, data-method, data-type and data-url
|
313
|
-
#
|
314
|
-
@dataArgumentOn = (elem) ->
|
315
|
-
$(elem).data()
|
316
|
-
|
317
|
-
#
|
318
|
-
# closeNotice
|
319
|
-
# will close the notice DIV
|
320
|
-
@closeNotice = (e) ->
|
321
|
-
fadeItOut $(e).closest('.alert') #.remove()
|
322
|
-
|
323
|
-
#
|
324
|
-
# PageOnLoad loads and initializes
|
325
|
-
# fixed elements like SELECT's, Materialized's elements, et al.
|
326
|
-
#
|
327
|
-
@pageOnLoad = () ->
|
328
|
-
|
329
|
-
# fileApiSupportCheck()
|
330
|
-
#
|
331
|
-
# make sure all eventhandlers are gone!
|
332
|
-
$(document.body).unbind('click.close_notice')
|
333
|
-
$(document.body).unbind('click.print')
|
334
|
-
$(document.body).unbind('click.delete')
|
335
|
-
$(document.body).unbind('click.fab')
|
336
|
-
$(document.body).unbind('click.attach')
|
337
|
-
$(document.body).unbind('click.activate')
|
338
|
-
$(document.body).unbind('click.prefer')
|
339
|
-
$(document.body).unbind('keydown.search')
|
340
|
-
$(document.body).unbind('click.search')
|
341
|
-
|
342
|
-
#
|
343
|
-
# Initialize the 'hamburger'
|
344
|
-
#
|
345
|
-
$(".button-collapse").sideNav();
|
346
|
-
|
347
|
-
#
|
348
|
-
# Prepare close-notice's for acting on clicks to remove div
|
349
|
-
#
|
350
|
-
$(document.body).on 'click.close_notice', 'a.close-notice', closeNotice
|
351
|
-
|
352
|
-
#
|
353
|
-
# Prepare print_link's
|
354
|
-
#
|
355
|
-
$(document.body).on 'click.print', 'a.print_post_link, a.print_item', handlePrintLinks
|
356
|
-
|
357
|
-
#
|
358
|
-
# Prepare delete_link's for acting on clicks to delete posts
|
359
|
-
#
|
360
|
-
$(document.body).on 'click.delete', 'a.delete_link, a.delete_item', handleDeleteLinks
|
361
|
-
|
362
|
-
#
|
363
|
-
# Add event on the FAB (fixed action button)
|
364
|
-
#
|
365
|
-
$(document.body).on 'click.fab', 'a.fab-button', handleFABLinks
|
366
|
-
|
367
|
-
#
|
368
|
-
# else
|
369
|
-
# $form = $(e.currentTarget).closest('form')
|
370
|
-
# data = $form.serialize()
|
371
|
-
# jqxhr = $.ajax
|
372
|
-
# url: $(e.currentTarget).data('url'),
|
373
|
-
# type: $(e.currentTarget).data('method'),
|
374
|
-
# data: data
|
375
|
-
# .done (response) ->
|
376
|
-
# $('body').html(response)
|
377
|
-
# .fail (response) ->
|
378
|
-
# console.log 'øv!'
|
379
|
-
|
380
|
-
#
|
381
|
-
# Initialize collapsible (uncomment the line below if you use the dropdown variation)
|
382
|
-
#
|
383
|
-
$('.collapsible').collapsible
|
384
|
-
accordion : true # A setting that changes the collapsible behavior to expandable instead of the default accordion style
|
385
|
-
|
386
|
-
#
|
387
|
-
# If this page has FORM element(s)
|
388
|
-
#
|
389
|
-
$('form').first().map (k,f) ->
|
390
|
-
initializeForm(f)
|
391
|
-
prepareUpload(f)
|
392
|
-
|
393
|
-
#
|
394
|
-
# If this page has a resources_list
|
395
|
-
#
|
396
|
-
$('table.resources_table').map (k,t) ->
|
397
|
-
console.log 'table ' + k
|
398
|
-
$(document.body).on 'click.attach', 'a.attached, a.detached', handleAttachLinks
|
399
|
-
$(document.body).on 'click.activate', 'a.activated, a.deactivated', handleActivateLinks
|
400
|
-
$(document.body).on 'click.prefer', 'a.preferred, a.deferred', handlePreferredLinks
|
401
|
-
scrollTable(t)
|
402
|
-
|
403
|
-
#
|
404
|
-
# Try to keep users from double-clicking submit's
|
405
|
-
#
|
406
|
-
# document.addEventListener('DOMContentLoaded', disableMultipleSubmits, false);
|
407
|
-
|
408
|
-
#
|
409
|
-
# make drop-downs react nicely
|
410
|
-
#
|
411
|
-
$(".dropdown-button").dropdown()
|
412
|
-
|
413
|
-
#
|
414
|
-
# prepare for tabbed display of tabbed UL's
|
415
|
-
#
|
416
|
-
$('ul.tabs').tabs()
|
417
|
-
$('.materialboxed').materialbox()
|
418
|
-
|
419
|
-
try
|
420
|
-
|
421
|
-
if ($('.sweet-alert').length<1)
|
422
|
-
initializeSweetAlert()
|
423
|
-
if ($('.sweet-alert').length>0)
|
424
|
-
console.log 'sweet-alert initialized correctly!' #swal( 'pageOnLoad', 'pageOnLoad blev kaldt!', 'success')
|
425
|
-
|
426
|
-
catch error
|
427
|
-
console.log 'autch!'
|
428
|
-
console.log error
|
429
|
-
|
430
|
-
# try
|
431
|
-
#
|
432
|
-
# swal( 'pageOnLoad', 'pageOnLoad blev kaldt!', 'success')
|
433
|
-
#
|
434
|
-
# catch error
|
435
|
-
# console.log 'ok - giving up'
|
436
|
-
# console.log 'page loaded!'
|
437
|
-
|
438
|
-
#
|
439
|
-
# check to see iff this browser supperts the File APIs
|
440
|
-
#
|
441
|
-
@fileApiSupportCheck = () ->
|
442
|
-
if (window.File && window.FileReader && window.FileList && window.Blob)
|
443
|
-
# All the File APIs are supported.
|
444
|
-
console.log 'file APIs supported '
|
445
|
-
else
|
446
|
-
document.getElementById('message_container').innerHTML = '<div class="alert fade in alert-warning"><a href="#!" class="warning close-notice btn-floating btn-small waves-effect waves-light" aria-hidden="true" type="button" data-dismiss="alert"><i class="material-icons">close</i></a>This browser does not support this application fully! Use latest Chrome - or advance cautiously!</div>';
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
#
|
452
|
-
# PageOnChange really just calls a pageload - as of now 19-06-15
|
453
|
-
# fixed elements like SELECT's, Materialized's elements, et al.
|
454
|
-
#
|
455
|
-
# @pageOnChange = () ->
|
456
|
-
# console.log 'page changed '
|
457
|
-
# pageOnLoad()
|