<commit_before>/* global $ */
import Active from './Active'
import Control from './Control'
import Mapper from './Mapper'
import Visualize from './Visualize'

const SynapseCard = {
  openSynapseCard: null,
  showCard: function(edge, e) {
    var self = SynapseCard

    // reset so we don't interfere with other edges, but first, save its x and y
    var myX = $('#edit_synapse').css('left')
    var myY = $('#edit_synapse').css('top')
    $('#edit_synapse').remove()

    // so label is missing while editing
    Control.deselectEdge(edge)

    var index = edge.getData('displayIndex') ? edge.getData('displayIndex') : 0
    var synapse = edge.getData('synapses')[index] // for now, just get the first synapse

    // create the wrapper around the form elements, including permissions
    // classes to make best_in_place happy
    var editDiv = document.createElement('div')
    editDiv.innerHTML = '<div id="editSynUpperBar"></div><div id="editSynLowerBar"></div>'
    editDiv.setAttribute('id', 'edit_synapse')
    if (synapse.authorizeToEdit(Active.Mapper)) {
      editDiv.className = 'permission canEdit'
      editDiv.className += synapse.authorizePermissionChange(Active.Mapper) ? ' yourEdge' : ''
    } else {
      editDiv.className = 'permission cannotEdit'
    }
    $('#wrapper').append(editDiv)

    self.populateShowCard(edge, synapse)

    // drop it in the right spot, activate it
    $('#edit_synapse').css('position', 'absolute')
    if (e) {
      $('#edit_synapse').css('left', e.clientX)
      $('#edit_synapse').css('top', e.clientY)
    } else {
      $('#edit_synapse').css('left', myX)
      $('#edit_synapse').css('top', myY)
    }
    // $('#edit_synapse_name').click() //required in case name is empty
    // $('#edit_synapse_name input').focus()
    $('#edit_synapse').show()

    self.openSynapseCard = edge
  },

  hideCard: function() {
    $('#edit_synapse').remove()
    SynapseCard.openSynapseCard = null
  },

  populateShowCard: function(edge, synapse) {
    var self = SynapseCard

    self.add_synapse_count(edge)
    self.add_desc_form(synapse)
    self.add_drop_down(edge, synapse)
    self.add_user_info(synapse)
    self.add_perms_form(synapse)
    self.add_direction_form(synapse)
  },
  add_synapse_count: function(edge) {
    var count = edge.getData('synapses').length

    $('#editSynUpperBar').append('<div id="synapseCardCount">' + count + '</div>')
  },
  add_desc_form: function(synapse) {
    var dataNil = 'Click to add description.'

    // TODO make it so that this would work even in sandbox mode,
    // currently with Best_in_place it won't

    // desc editing form<commit_msg>fix editing synapse desc (#1101)<commit_after>/* global $ */
import Active from './Active'
import Control from './Control'
import Mapper from './Mapper'
import Visualize from './Visualize'

const SynapseCard = {
  openSynapseCard: null,
  showCard: function(edge, e) {
    var self = SynapseCard

    // reset so we don't interfere with other edges, but first, save its x and y
    var myX = $('#edit_synapse').css('left')
    var myY = $('#edit_synapse').css('top')
    $('#edit_synapse').remove()

    // so label is missing while editing
    Control.deselectEdge(edge)

    var index = edge.getData('displayIndex') ? edge.getData('displayIndex') : 0
    var synapse = edge.getData('synapses')[index] // for now, just get the first synapse

    // create the wrapper around the form elements, including permissions
    // classes to make best_in_place happy
    var editDiv = document.createElement('div')
    editDiv.innerHTML = '<div id="editSynUpperBar"></div><div id="editSynLowerBar"></div>'
    editDiv.setAttribute('id', 'edit_synapse')
    if (synapse.authorizeToEdit(Active.Mapper)) {
      editDiv.className = 'permission canEdit'
      editDiv.className += synapse.authorizePermissionChange(Active.Mapper) ? ' yourEdge' : ''
    } else {
      editDiv.className = 'permission cannotEdit'
    }
    $('#wrapper').append(editDiv)

    self.populateShowCard(edge, synapse)

    // drop it in the right spot, activate it
    $('#edit_synapse').css('position', 'absolute')
    if (e) {
      $('#edit_synapse').css('left', e.clientX)
      $('#edit_synapse').css('top', e.clientY)
    } else {
      $('#edit_synapse').css('left', myX)
      $('#edit_synapse').css('top', myY)
    }
    // $('#edit_synapse_name').click() //required in case name is empty
    // $('#edit_synapse_name input').focus()
    $('#edit_synapse').show()

    self.openSynapseCard = edge
  },

  hideCard: function() {
    $('#edit_synapse').remove()
    SynapseCard.openSynapseCard = null
  },

  populateShowCard: function(edge, synapse) {
    var self = SynapseCard

    self.add_synapse_count(edge)
    self.add_desc_form(synapse)
    self.add_drop_down(edge, synapse)
    self.add_user_info(synapse)
    self.add_perms_form(synapse)
    self.add_direction_form(synapse)
    $('.authenticated #edit_synapse.permission.canEdit .best_in_place').best_in_place()
  },
  add_synapse_count: function(edge) {
    var count = edge.getData('synapses').length

    $('#editSynUpperBar').append('<div id="synapseCardCount">' + count + '</div>')
  },
  add_desc_form: function(synapse) {
    var dataNil = 'Click to add description.'

    // TODO make it so that this would work even in sandbox mode,
    // currently with Best_in_place it won't

    // desc editing form
{'fraction_non_alphanumeric': 0.1478180129990715, 'fraction_numerical': 0.0011142061281337048, 'mean_word_length': 3.5838297872340426, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5145200', 'n_tokens_mistral': 1714, 'n_tokens_neox': 1685, 'n_words': 402}