-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #309 from keitaroinc/feature/tags-ui
Feature/tags ui
- Loading branch information
Showing
14 changed files
with
429 additions
and
14 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
ckanext/knowledgehub/fanstatic/javascript/user_profile_tags.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
(function (_, jQuery) { | ||
'use strict'; | ||
|
||
var api = { | ||
get: function (action, params) { | ||
var api_ver = 3; | ||
var base_url = ckan.sandbox().client.endpoint; | ||
params = $.param(params); | ||
var url = base_url + '/api/' + api_ver + '/action/' + action + '?' + params; | ||
return $.getJSON(url); | ||
}, | ||
post: function (action, data) { | ||
var api_ver = 3; | ||
var base_url = ckan.sandbox().client.endpoint; | ||
var url = base_url + '/api/' + api_ver + '/action/' + action; | ||
return $.post(url, data, 'json'); | ||
} | ||
}; | ||
|
||
function removeTag(tr) { | ||
var tagID = tr.get(0).cells[0].innerHTML; | ||
|
||
api.post('tag_delete', { | ||
id: tagID | ||
}) | ||
.done(function (data) { | ||
if (data.success) { | ||
tr.detach(); | ||
} | ||
}) | ||
.fail(function (error) { | ||
console.log("Tag delete: " + error.statusText); | ||
}); | ||
}; | ||
|
||
function updateTag(tagID, vocabularyID, loader) { | ||
loader.css("visibility", "visible"); | ||
api.get('tag_show', { | ||
id: tagID | ||
}) | ||
.done(function (data) { | ||
if (data.success) { | ||
var name = data.result.name | ||
api.post('tag_update', { | ||
id: tagID, | ||
name: name, | ||
vocabulary_id: vocabularyID | ||
}) | ||
.fail(function (error) { | ||
console.log("Tag update: " + error.statusText); | ||
}) | ||
} | ||
}) | ||
.fail(function (error) { | ||
console.log("Tag show: " + error.statusText); | ||
}); | ||
setTimeout(function () { | ||
loader.css("visibility", "hidden"); | ||
}, 500); | ||
} | ||
|
||
$(document).ready(function () { | ||
var $table = $('#tags'); | ||
$table.DataTable({ | ||
"paging": true, | ||
"iDisplayLength": 25 | ||
}); | ||
|
||
$('.dataTables_length').addClass('bs-select'); | ||
$table.removeClass('dataTable'); | ||
|
||
var modalConfirm = function (callback) { | ||
var tr; | ||
var modalDelete = $('#modalDelete'); | ||
|
||
$table.on('click', '.table-remove', function () { | ||
tr = $(this).parents('tr'); | ||
modalDelete.modal('show'); | ||
}); | ||
|
||
$('#btnYes').on('click', function () { | ||
callback(true, tr); | ||
modalDelete.modal('hide'); | ||
}); | ||
|
||
$('#btnNo').on('click', function () { | ||
callback(false, tr); | ||
modalDelete.modal('hide'); | ||
}) | ||
} | ||
|
||
modalConfirm(function (confirm, tr) { | ||
if (confirm) { | ||
removeTag(tr); | ||
} | ||
}); | ||
|
||
document.querySelectorAll('#keyword-select').forEach(item => { | ||
item.addEventListener('change', event => { | ||
var vocabularyID = event.target.value; | ||
var parentRow = event.target.parentElement.parentElement; | ||
var tagID = parentRow.cells[0].innerHTML; | ||
var loader = $(event.target).closest('td').find('#loader'); | ||
updateTag(tagID, vocabularyID, loader); | ||
}) | ||
}) | ||
}); | ||
})(ckan.i18n.ngettext, $); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.