mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-11-04 01:12:08 +01:00 
			
		
		
		
	Added a 'trust back' button, front can be improved
This commit is contained in:
		@@ -1,7 +1,7 @@
 | 
			
		||||
/**
 | 
			
		||||
 * On form submit, create a new friendship
 | 
			
		||||
 */
 | 
			
		||||
function create_trust (e) {
 | 
			
		||||
function form_create_trust (e) {
 | 
			
		||||
  // Do not submit HTML form
 | 
			
		||||
  e.preventDefault()
 | 
			
		||||
 | 
			
		||||
@@ -14,25 +14,35 @@ function create_trust (e) {
 | 
			
		||||
         addMsg(gettext("You can't add yourself as a friend"), "danger")
 | 
			
		||||
         return
 | 
			
		||||
      }
 | 
			
		||||
      $.post('/api/note/trust/', {
 | 
			
		||||
        csrfmiddlewaretoken: formData.get('csrfmiddlewaretoken'),
 | 
			
		||||
        trusting: formData.get('trusting'),
 | 
			
		||||
        trusted: trusted_alias.note
 | 
			
		||||
      }).done(function () {
 | 
			
		||||
        // Reload table
 | 
			
		||||
        $('#trust_table').load(location.pathname + ' #trust_table')
 | 
			
		||||
        addMsg(gettext('Friendship successfully added'), 'success')
 | 
			
		||||
      }).fail(function (xhr, _textStatus, _error) {
 | 
			
		||||
        errMsg(xhr.responseJSON)
 | 
			
		||||
      })
 | 
			
		||||
      create_trust(formData.get('trusting'), trusted_alias.note)
 | 
			
		||||
    }).fail(function (xhr, _textStatus, _error) {
 | 
			
		||||
        errMsg(xhr.responseJSON)
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * On click of "delete", delete the alias
 | 
			
		||||
 * @param button_id:Integer Alias id to remove
 | 
			
		||||
 * Create a trust between users
 | 
			
		||||
 * @param trusting:Integer trusting note id
 | 
			
		||||
 * @param trusted:Integer trusted note id
 | 
			
		||||
 */
 | 
			
		||||
function create_trust(trusting, trusted) {
 | 
			
		||||
  $.post('/api/note/trust/', {
 | 
			
		||||
      trusting: trusting,
 | 
			
		||||
      trusted: trusted,
 | 
			
		||||
      csrfmiddlewaretoken: CSRF_TOKEN
 | 
			
		||||
  }).done(function () {
 | 
			
		||||
  // Reload tables
 | 
			
		||||
  $('#trust_table').load(location.pathname + ' #trust_table')
 | 
			
		||||
  $('#trusted_table').load(location.pathname + ' #trusted_table')
 | 
			
		||||
    addMsg(gettext('Friendship successfully added'), 'success')
 | 
			
		||||
  }).fail(function (xhr, _textStatus, _error) {
 | 
			
		||||
    errMsg(xhr.responseJSON)
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * On click of "delete", delete the trust
 | 
			
		||||
 * @param button_id:Integer Trust id to remove
 | 
			
		||||
 */
 | 
			
		||||
function delete_button (button_id) {
 | 
			
		||||
  $.ajax({
 | 
			
		||||
@@ -42,6 +52,7 @@ function delete_button (button_id) {
 | 
			
		||||
  }).done(function () {
 | 
			
		||||
    addMsg(gettext('Friendship successfully deleted'), 'success')
 | 
			
		||||
    $('#trust_table').load(location.pathname + ' #trust_table')
 | 
			
		||||
    $('#trusted_table').load(location.pathname + ' #trusted_table')
 | 
			
		||||
  }).fail(function (xhr, _textStatus, _error) {
 | 
			
		||||
    errMsg(xhr.responseJSON)
 | 
			
		||||
  })
 | 
			
		||||
@@ -49,5 +60,5 @@ function delete_button (button_id) {
 | 
			
		||||
 | 
			
		||||
$(document).ready(function () {
 | 
			
		||||
  // Attach event
 | 
			
		||||
  document.getElementById('form_trust').addEventListener('submit', create_trust)
 | 
			
		||||
  document.getElementById('form_trust').addEventListener('submit', form_create_trust)
 | 
			
		||||
})
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user