First steps for editing.
parent
64ccd26dce
commit
c320a358db
|
@ -2,6 +2,31 @@
|
||||||
|
|
||||||
var Snipt = snipt.module('snipt');
|
var Snipt = snipt.module('snipt');
|
||||||
|
|
||||||
|
Backbone.oldSync = Backbone.sync;
|
||||||
|
Backbone.Model.prototype.idAttribute = 'resource_uri';
|
||||||
|
var addSlash = function(str) {
|
||||||
|
return str + ((str.length > 0 && str.charAt(str.length - 1) === '/') ? '' : '/');
|
||||||
|
};
|
||||||
|
Backbone.sync = function(method, model, options) {
|
||||||
|
options.headers = _.extend({
|
||||||
|
'Authorization': 'ApiKey ' + window.user + ':' + window.api_key
|
||||||
|
}, options.headers);
|
||||||
|
return Backbone.oldSync(method, model, options);
|
||||||
|
};
|
||||||
|
Backbone.Model.prototype.url = function() {
|
||||||
|
var url = this.id;
|
||||||
|
if (!url) {
|
||||||
|
url = this.urlRoot;
|
||||||
|
url = url || this.collection && (_.isFunction(this.collection.url) ? this.collection.url() : this.collection.url);
|
||||||
|
|
||||||
|
if (url && this.has('id')) {
|
||||||
|
url = addSlash(url) + this.get('id');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
url = url && addSlash(url);
|
||||||
|
return url || null;
|
||||||
|
};
|
||||||
|
|
||||||
Site.SiteView = Backbone.View.extend({
|
Site.SiteView = Backbone.View.extend({
|
||||||
el: 'body',
|
el: 'body',
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,6 @@
|
||||||
(function(Snipt) {
|
(function(Snipt) {
|
||||||
|
|
||||||
Backbone.oldSync = Backbone.sync;
|
|
||||||
Backbone.sync = function(method, model, options) {
|
|
||||||
options.headers = _.extend({
|
|
||||||
'Authorization': 'ApiKey ' + window.user + ':' + window.api_key
|
|
||||||
}, options.headers);
|
|
||||||
return Backbone.oldSync(method, model, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
Snipt.SniptModel = Backbone.Model.extend({
|
Snipt.SniptModel = Backbone.Model.extend({
|
||||||
urlRoot: '/api/private/snipt/'
|
|
||||||
});
|
});
|
||||||
Snipt.SniptView = Backbone.View.extend({
|
Snipt.SniptView = Backbone.View.extend({
|
||||||
|
|
||||||
|
@ -127,7 +118,11 @@
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
$('button.save', window.site.$main_edit).on('click', function(e) {
|
$('button.save', window.site.$main_edit).on('click', function(e) {
|
||||||
|
that.model.set('title', $('input#snipt_title').val());
|
||||||
that.model.save();
|
that.model.save();
|
||||||
|
|
||||||
|
window.site.snipt_list.escapeUI();
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<header>
|
<header>
|
||||||
<h2> </h2>
|
<h2> </h2>
|
||||||
<h1>
|
<h1>
|
||||||
<input type="text" value="<%= snipt.title %>" />
|
<input type="text" id="snipt_title" value="<%= snipt.title %>" />
|
||||||
</h1>
|
</h1>
|
||||||
</header>
|
</header>
|
||||||
<section class="code">
|
<section class="code">
|
||||||
|
|
Loading…
Reference in New Issue