Created
August 19, 2011 16:03
-
-
Save schenkman/1157190 to your computer and use it in GitHub Desktop.
Adding click event to button
This file contains hidden or 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
| 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='✓' /><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