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'));
var ItemTemplate = require('tpl!temlates/item.html');
app.ItemView = Backbone.View.extend({
template: _.template('<li><%= item_title %></li>'),
render: function () {
this.el = this.template(this.model.toJSON());
this.addAll();
return this;
}
addAll: function() {
this.collection.each(this.addOne);
},
addOne: function (item) {
this.$el.append(ItemTemplate({
item:item
}));
}
});
user.save({}, {
success: function(response) {
if (response.token) {
localStorage.setItem('access_token', response.token);
window.workspace.navigate('#', { trigger: true});
}},
error: function(response) {
var error = JSON.parse(response.responseText)
}
Backbone._sync = Backbone.sync
Backbone._sync = function(method, model, options) {
options = $.extend({
crossDomain: true
, xhrFields: {
withCredentials: true
}
, beforeSend: function(xhr){
xhr.setRequestHeader('Authorization', 'Token ' + localStorage.getItem('access_token'));
}
}, options);
return Backbone._sync(method, model, options);
}