Skip to content

Commit

Permalink
Start of admin page - resources
Browse files Browse the repository at this point in the history
See #22
  • Loading branch information
bates64 committed Jul 4, 2016
1 parent 4fba8ab commit a256c70
Show file tree
Hide file tree
Showing 10 changed files with 420 additions and 177 deletions.
2 changes: 0 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,13 @@ gulp.task('build-js', ['clean-js'], function() {
gulp.task('build-css', ['clean-css'], function() {
return gulp.src('public/assets/css/main.styl')
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(stylus({
compress: true,
use: [
require('rupture')()
]
}))
.pipe(postcss([ require('autoprefixer')(), require('rucksack-css')() ]))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('public/assets/css/.dist'))
})

Expand Down
60 changes: 60 additions & 0 deletions public/assets/js/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const ajax = require('axios')

async function del(e) {
let btn = e.target
let res = btn.parentNode
let to = btn.attributes['data-to'].value

if(!window.confirm('Are you sure you\'d like to delete this?')) {
btn.innerHTML = 'delete'
return
}

await ajax({
url: to,
method: 'delete',
headers: {
'X-CSRF-Token': window.csrf
}
})

if(btn.attributes['data-sure']) {
window.location.href = '/you'
} else {
btn.innerHTML = 'undelete'
}
}

async function undelete(e) {
let btn = e.target
let res = btn.parentNode
let to = btn.attributes['data-to'].value

await ajax({
url: to,
method: 'post',
headers: {
'X-CSRF-Token': window.csrf
}
})

btn.innerHTML = 'delete'
}

module.exports = function() {
let btns = document.querySelectorAll('.btn.admin-do')

for(let i = 0; i < btns.length; i++) {
let btn = btns[i]

btn.addEventListener('click', function(e) {
if(btn.innerText == 'delete') {
btn.innerHTML = 'deleting...'
del(e)
} else {
btn.innerHTML = 'undeleting...'
undelete(e)
}
})
}
}
5 changes: 4 additions & 1 deletion public/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const md = require('./md')
const timeago = require('./timeago')
const resources = require('./resources')
const resource_page = require('./resource_page')

const admin = require('./admin')
const visualizer = require('./visualizer')

if('/join' === window.location.pathname)
Expand All @@ -20,6 +20,9 @@ if('/join' === window.location.pathname)
if('/share' === window.location.pathname)
share()

if(document.querySelector('.btn.admin-do'))
admin()

if(document.querySelector('.markdown-about-edit'))
md()

Expand Down
Loading

0 comments on commit a256c70

Please sign in to comment.