Skip to content

Instantly share code, notes, and snippets.

@schenkman
Created August 19, 2011 16:03
Show Gist options
  • Select an option

  • Save schenkman/1157190 to your computer and use it in GitHub Desktop.

Select an option

Save schenkman/1157190 to your computer and use it in GitHub Desktop.
Adding click event to button
var formNote = "";
formNote += "<div class='hs_note'>";
formNote += "<form id='note_edit_form' action='/accounts/" + account_class + "/" + account_id + "/"+noteAction+"' method='post' data-remote='true'>";
formNote += "<div style='margin:0;padding:0;display:inline'><input name='utf8' type='hidden' value='&#x2713;' /><input name='authenticity_token' type='hidden' value='"+$("meta[name=csrf-token]").attr("content")+"' /></div>";
formNote += "<input type='hidden' name='note[metric]' value='" + metric + "'>";
formNote += "<input type='hidden' name='note[date]' value='" + dateformat + "'>";
if(note_id!=undefined) {
formNote += "<input type='hidden' name='note[id]' value='" + note_id + "'>";
}
formNote += "<textarea name='note[content]' class='textNote' cols='32' rows='7'>"+note_text+"</textarea><br>";
formNote += "<input type='submit' value='Submit' />";
formNote += "<input type='submit' id='note_edit_cancel' value='Cancel'>";
formNote += "</form>"
formNote += "</div>";
var slot = $('.slot');
slot.append(formNote);
//check if there are edits that need to be verified on cancel
$('#note_edit_cancel').click(function() {
//if this is a new note and the text is not blank, confirm cancel
if(note_id==undefined && $('[name="note[content]"]').val()!='') {
if(!confirm("Are you sure you want to discard your new note?")) {
$('.textNote').focus();
return false;
}
}
else if(note_id!=undefined && $('[name="note[content]"]').val()!=$('#note_'+note_id+'_text').html()) {
if(!confirm("Are you sure you want to discard your edits?")) {
$('.textNote').focus();
return false;
}
}
//discard note edit
$('.hs_note').remove();
hs.getExpander().reflow();
$('.note_edit').attr("class","note");
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment