App.Views.NewPing = Backbone.View.extend({ events:{ "submit form" : "ping" }, initialize: function() { var name = this.model.get('name'); this.render(name); this.model.new_ping(name); if(name == undefined) this.model.get_users('ping'); }, ping: function(e) { e.preventDefault(); var users = $('#pinguser').val().split(','); var message = $('#pingmessage').val(); var vibrate = $('#pingvibrate').val(); var sound = $('#pingsound').val(); var badge = $('#pingbadge').val(); var sources = $('#sources').val().split(','); $.ajax({ type: 'POST', url: '/api/client/ping', data: {api_token : this.model.get('api_token'), user_id : users, message : message, vibrate : vibrate, badge : badge, sources : sources}, success: function(){ router.navigate("users", true); }, error: function(resp){ if(resp.status == 422){ new App.Views.Index() } $('#ping-alert')[0].innerHTML = resp.responseText; $('#ping-alert').css('display','block'); } }) }, render: function(name) { $('#secondary-nav').css('display','block'); out = ""; out += ""; out += "
"; out += ""; out += ""; out += ""; out += ""; out += ""; out += "" out += "" out += "
Message:
Sources
Sound
Badge
Vibrate (seconds)
"; $(this.el).html(out); $('#main_content').html(this.el); } });