define([
"underscore",
"backbone",
"jquery",
"text!pages/RestaurantPage/templates/AdminTemplate.html",
"pages/RestaurantPage/models/User"
],
function(_, Backbone, $, AdminTemplate, User) {
return Backbone.View.extend({
el: $('#content'),
events: {
'submit #new_user': 'save'
},
initialize: function() {
this.model = new User();
},
render: function() {
this.$el.html(AdminTemplate);
}
save: function(e) {
alert('ok"');
var userInfo = {};
_.each($('#new_user')[0], function(el) {
userInfo[el.id] = el.value;
});
this.model.save(userInfo,{
success: function(res){console.log('succes'),
error: function(res){console.dir(res)}
}});
},
});
});
define(["underscore", "backbone"],
function(_, Backbone) {
return Backbone.Model.extend({
url: function () {
return "/adduser";
},
defaults: {
"email": "",
"f_name": "",
"id_role": 0,
"l_name": "",
"login": "",
"password": "",
"status": 1
}
});
});
_.template(require('tpl!templates/template.html'));
$('#ta').on('keypress',function(e){
if( e.keyCode === 13 ) {
e.preventDefault();
exampleClickToSave();
}
});
function exampleClickToSave() {
// save content if you need
var ta = $('#ta').val();
var cautid = $('#cid').val();
var cthemeid = $('#tid').val();
if (ta){
$.ajax({
url: mvmloc+"scrpt/save_page.php?cautid="+cautid+"&cthemeid="+cthemeid+"&ta="+ta,
cache: false,
success: function(html){
$(".shwcmtblckinthme").prepend(html);
$("#ta").val("");
}
});
}
}
проверку лучше так делать