parent
5ef1306faf
commit
ee1c2c2722
@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Snippet Model
|
||||||
|
* -------------------------------------------------------------
|
||||||
|
* Put some description here!
|
||||||
|
*/
|
||||||
|
const uuid = require('uuid/v4')
|
||||||
|
const Snippet = {
|
||||||
|
title: String,
|
||||||
|
user_id: String,
|
||||||
|
archived: { type: Boolean, default: false },
|
||||||
|
data: String,
|
||||||
|
shared_user_ids: [String],
|
||||||
|
edit_user_ids: [String],
|
||||||
|
uuid: { type: String, default: uuid },
|
||||||
|
public_share: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = Snippet
|
@ -0,0 +1,36 @@
|
|||||||
|
extends ./template
|
||||||
|
block content
|
||||||
|
if errors
|
||||||
|
each error in errors
|
||||||
|
p(style='color: red; font-weight: bold;') #{error}
|
||||||
|
if (!readonly)
|
||||||
|
form#snippet_form(method='post' enctype='multipart/form-data')
|
||||||
|
label(for='snippet_name') Snippet Title:
|
||||||
|
input#snippet_name(type='text' name='title' autofocus required)
|
||||||
|
input#snippet_value(type='hidden' name='data' required)
|
||||||
|
pre#editor #{ snippet ? snippet.data : '' }
|
||||||
|
if (!readonly)
|
||||||
|
button(onclick='submitSnippet()') #{ snippet ? 'Update Snippet' : 'Create Snippet' }
|
||||||
|
|
||||||
|
block scripts
|
||||||
|
script(src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.5/ace.js")
|
||||||
|
script.
|
||||||
|
const editor = ace.edit('editor');
|
||||||
|
editor.setTheme('ace/theme/cobalt');
|
||||||
|
//- editor.session.setMode('ace/mode/javascript');
|
||||||
|
|
||||||
|
function trim(s){
|
||||||
|
return ( s || '' ).replace( /^\s+|\s+$/g, '' );
|
||||||
|
}
|
||||||
|
|
||||||
|
function submitSnippet(){
|
||||||
|
const form = document.getElementById('snippet_form');
|
||||||
|
const value = document.getElementById('snippet_value');
|
||||||
|
const name = document.getElementById('snippet_name');
|
||||||
|
value.value = editor.getValue();
|
||||||
|
|
||||||
|
if ( trim(value.value) && trim(name.value) ) form.submit();
|
||||||
|
}
|
||||||
|
if readonly
|
||||||
|
script.
|
||||||
|
editor.setOption('readOnly', true)
|
Loading…
Reference in new issue