Skip to content

Commit

Permalink
Merge pull request #1378 from SynBioHub/fixButtons
Browse files Browse the repository at this point in the history
Fix JQuery buttons
  • Loading branch information
cjmyers authored Nov 3, 2020
2 parents a30b79f + 942bd27 commit c8d94da
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
32 changes: 16 additions & 16 deletions browser/synbiohub.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ $(document).on('click', '.removeFromWoR', function() {
})

$(document).on('blur', '#user_edit #email', function() {
$username = $('#username');
$email = $(this).closest('#email');
const $username = $('#username');
const $email = $(this).closest('#email');

let email = $email.val();
let username = email.split('@')[0].replace(/\W/g, '');
Expand All @@ -78,8 +78,8 @@ $(document).on('blur', '#user_edit #email', function() {
})

$(document).on('blur', '#new #name', function() {
$id = $('input#id');
$name = $(this).closest('input#name');
const $id = $('input#id');
const $name = $(this).closest('input#name');

let name = $name.val();
let id = "";
Expand Down Expand Up @@ -188,7 +188,7 @@ $(document).on('click', '.sbh-collection-members-datatable .remove', function ()

function createPluginFunctions(pluginType) {
$(document).on('click', '.save-' + pluginType + '-plugin', function () {
$row = $(this).closest('tr')
const $row = $(this).closest('tr')

var pluginInfo = {
id: $row.find("#id").text(),
Expand All @@ -203,7 +203,7 @@ function createPluginFunctions(pluginType) {
})

$(document).on('click', '.delete-' + pluginType + '-plugin', function () {
$row = $(this).closest('tr')
const $row = $(this).closest('tr')

var pluginInfo = {
id: $row.find("#id").text(),
Expand Down Expand Up @@ -232,7 +232,7 @@ $('.sbh-registries-datatable').DataTable({
})

$(document).on('click', '.save-registry', function () {
$row = $(this).closest('tr')
const $row = $(this).closest('tr')

var registryInfo = {
uri: $row.find('#uri').val(),
Expand All @@ -243,7 +243,7 @@ $(document).on('click', '.save-registry', function () {
})

$(document).on('click', '.delete-registry', function () {
$row = $(this).closest('tr')
const $row = $(this).closest('tr')

var registryInfo = {
uri: $row.find('#uri').val(),
Expand Down Expand Up @@ -621,19 +621,19 @@ function getFields(type) {
}

function clearForm() {
$form = $('#remoteForm').empty();
var $form = $('#remoteForm').empty();
}

function populateForm(type, data) {
$form = $('#remoteForm');
var $form = $('#remoteForm');

const fields = getFields(type);

Object.keys(fields).forEach(key => {
fieldInfo = fields[key];
var fieldInfo = fields[key];

$label = $("<label />").attr("for", key).text(fieldInfo.name);
$input = {
var $label = $("<label />").attr("for", key).text(fieldInfo.name);
var $input = {
"text": $("<input />").attr("type", "text").val(fieldInfo.default),
"checkbox": $("<input />").attr("type", "checkbox").prop("checked", fieldInfo.default),
"textarea": $("<textarea />").val(fieldInfo.default),
Expand All @@ -652,18 +652,18 @@ function populateForm(type, data) {
}
}

$group = $("<div />").addClass('form-group').append($label, $input)
var $group = $("<div />").addClass('form-group').append($label, $input)

$('#remoteForm').append($group)
})


}

$(document).on('click', '#remoteTypeSelect', function () {
$('#remoteTypeSelect').on('change', function () {
var type = $(this).val()

if (type != "") {
if (type !== "") {
clearForm();
$('#addRemote').attr('disabled', false);
populateForm(type, {"type": type})
Expand Down
14 changes: 11 additions & 3 deletions lib/api/editObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const sparql = require('../sparql/sparql')
const lookupRole = require('../role')
const lookupType = require('../type')
const URI = require('urijs')
const getOwnedBy = require('../query/ownedBy')

const PREDICATES = {
'title': 'http://purl.org/dc/terms/title',
Expand Down Expand Up @@ -59,10 +60,16 @@ function formatObject (field, object) {
}
}

function serve (req, res) {
async function serve (req, res) {
let { graphUri, uri } = getUrisFromReq(req, res)
let field = req.params.field

let ownedBy = await getOwnedBy(uri, graphUri)
if (ownedBy.indexOf(config.get('databasePrefix') + 'user/' + req.user.username) === -1) {
res.status(401).send('Not authorized to edit this object')
return
}

let d = new Date()
let modified = d.toISOString()
modified = modified.substring(0, modified.indexOf('.'))
Expand Down Expand Up @@ -96,12 +103,13 @@ function serve (req, res) {
subject: subject,
predicate: predicate,
object: formatObject(field, object),
previous: formatObject(field, previous),
previous: (field === 'title' || field === 'description') ? '?previous' : formatObject(field, previous),
modified: modified
}

const query = loadTemplate('./sparql/UpdateTriple.sparql', params)
console.log(query)
console.log('graphUri=' + graphUri)
console.log('query=' + query)

sparql.updateQueryJson(query, graphUri).then(result => {
res.send(getDisplayString(field, object))
Expand Down
3 changes: 0 additions & 3 deletions templates/views/admin/remotes.jade
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ block adminContent
a.btn.btn-info#remoteEdit(data-toggle="modal", data-target="#remoteModal")
span.fa.fa-pencil
| Edit
a.btn.btn-primary(href=remote.rootCollectionUrl + '/copyFromRemote/')
span.fa.fa-cloud-download
| Snapshot
div.col-md-1
div.col-md-3
table.table.table-striped
Expand Down

0 comments on commit c8d94da

Please sign in to comment.