2017-04-01 21:07:01 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
import $ from 'jquery'
|
|
|
|
import _ from 'lodash'
|
|
|
|
import { setInputSelection } from '../helpers/form'
|
|
|
|
import { makeSafePath } from '../helpers/pages'
|
2016-09-09 23:22:18 +00:00
|
|
|
|
2017-02-09 01:52:37 +00:00
|
|
|
// -> Create New Document
|
2016-09-09 23:22:18 +00:00
|
|
|
|
2017-04-01 21:07:01 +00:00
|
|
|
module.exports = (currentBasePath) => {
|
|
|
|
let suggestedCreatePath = currentBasePath + '/new-page'
|
2016-09-09 23:22:18 +00:00
|
|
|
|
2017-04-01 21:07:01 +00:00
|
|
|
$('.btn-create-prompt').on('click', (ev) => {
|
|
|
|
$('#txt-create-prompt').val(suggestedCreatePath)
|
|
|
|
$('#modal-create-prompt').toggleClass('is-active')
|
|
|
|
setInputSelection($('#txt-create-prompt').get(0), currentBasePath.length + 1, suggestedCreatePath.length)
|
|
|
|
$('#txt-create-prompt').removeClass('is-danger').next().addClass('is-hidden')
|
|
|
|
})
|
2016-09-09 23:22:18 +00:00
|
|
|
|
2017-04-01 21:07:01 +00:00
|
|
|
$('#txt-create-prompt').on('keypress', (ev) => {
|
|
|
|
if (ev.which === 13) {
|
|
|
|
$('.btn-create-go').trigger('click')
|
|
|
|
}
|
|
|
|
})
|
2016-09-09 23:22:18 +00:00
|
|
|
|
2017-04-01 21:07:01 +00:00
|
|
|
$('.btn-create-go').on('click', (ev) => {
|
|
|
|
let newDocPath = makeSafePath($('#txt-create-prompt').val())
|
|
|
|
if (_.isEmpty(newDocPath)) {
|
|
|
|
$('#txt-create-prompt').addClass('is-danger').next().removeClass('is-hidden')
|
|
|
|
} else {
|
|
|
|
$('#txt-create-prompt').parent().addClass('is-loading')
|
|
|
|
window.location.assign('/create/' + newDocPath)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|