diff options
author | Jason Croft | 2016-05-09 22:38:13 -0400 |
---|---|---|
committer | Jason Croft | 2016-05-09 22:38:13 -0400 |
commit | 70f6e5bc2cbdb15ff48bdf49b09d7c4bb78ea4ba (patch) | |
tree | b7726eee9cc32a416d95f526a0f0898a86aba946 /public | |
parent | 17d2249ec31bce28f79e8def4be1515ac465d29b (diff) |
Define events for snippet actions
Diffstat (limited to '')
-rw-r--r-- | public/js/index.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/public/js/index.js b/public/js/index.js index 0b10c9e0..17516169 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1136,6 +1136,8 @@ ui.toolbar.export.googleDrive.click(function (e) { }); //export to gist ui.toolbar.export.gist.attr("href", noteurl + "/gist"); +//export to snippet +ui.toolbar.export.snippet.attr("href", noteurl + "/snippet"); //import from dropbox ui.toolbar.import.dropbox.click(function () { var options = { @@ -1188,6 +1190,10 @@ function buildImportFromGoogleDrive() { ui.toolbar.import.gist.click(function () { //na }); +//import from snippet +ui.toolbar.import.snippet.click(function () { + //na +}); //import from clipboard ui.toolbar.import.clipboard.click(function () { //na @@ -1355,6 +1361,45 @@ $("#gistImportModalConfirm").click(function () { } }); +// snippet import modal +$("#snippetImportModalClear").click(function () { + $("#snippetImportModalContent").val(''); +}); +$("#snippetImportModalConfirm").click(function () { + var snippeturl = $("#snippetImportModalContent").val(); + if (!snippeturl) return; + $('#snippetImportModal').modal('hide'); + $("#snippetImportModalContent").val(''); + if (!isValidURL(snippeturl)) { + showMessageModal('<i class="fa fa-gitlab"></i> Import from Snippet', 'Not a valid URL :(', '', '', false); + return; + } else { + // TODO: Validate against config.gitlab.baseURL + ui.spinner.show(); + $.get(snippeturl) + .success(function (data) { + if (data.files) { + var contents = ""; + Object.keys(data.files).forEach(function (key) { + contents += key; + contents += '\n---\n'; + contents += data.files[key].content; + contents += '\n\n'; + }); + replaceAll(contents); + } else { + showMessageModal('<i class="fa fa-gitlab"></i> Import from Snippet', 'Unable to fetch snippet files :(', '', '', false); + } + }) + .error(function (data) { + showMessageModal('<i class="fa fa-gitlab"></i> Import from Snippet', 'Not a valid Snippet URL :(', '', JSON.stringify(data), false); + }) + .complete(function () { + ui.spinner.hide(); + }); + } +}); + function parseToEditor(data) { var parsed = toMarkdown(data); if (parsed) |