A ton of stuff for editing and deleting
parent
df6b1f5208
commit
ac7248f9a1
|
@ -9,7 +9,6 @@
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
this.model.view = this;
|
this.model.view = this;
|
||||||
this.model.bind('change', this.render, this);
|
this.model.bind('change', this.render, this);
|
||||||
this.model.bind('destroy', this.remove, this);
|
|
||||||
|
|
||||||
this.template = _.template($('#snipt').html());
|
this.template = _.template($('#snipt').html());
|
||||||
this.editTemplate = _.template($('#edit').html());
|
this.editTemplate = _.template($('#edit').html());
|
||||||
|
@ -23,19 +22,20 @@
|
||||||
'click a.expand': 'expand',
|
'click a.expand': 'expand',
|
||||||
'click .container': 'selectFromClick',
|
'click .container': 'selectFromClick',
|
||||||
'copyRaw': 'copy',
|
'copyRaw': 'copy',
|
||||||
'copyClose': 'copyClose',
|
|
||||||
'detail': 'detail',
|
'detail': 'detail',
|
||||||
'deselect': 'deselect',
|
'deselect': 'deselect',
|
||||||
'edit': 'edit',
|
'edit': 'edit',
|
||||||
'embed': 'embed',
|
'embed': 'embed',
|
||||||
'embedClose': 'embedClose',
|
|
||||||
'expand': 'expand',
|
'expand': 'expand',
|
||||||
|
'fadeAndRemove': 'fadeAndRemove',
|
||||||
'next': 'next',
|
'next': 'next',
|
||||||
'prev': 'prev',
|
'prev': 'prev',
|
||||||
'selectSnipt': 'select'
|
'selectSnipt': 'select'
|
||||||
},
|
},
|
||||||
|
|
||||||
copy: function() {
|
copy: function() {
|
||||||
|
$('textarea', this.$copyModal).remove();
|
||||||
|
|
||||||
window.ui_halted = true;
|
window.ui_halted = true;
|
||||||
|
|
||||||
this.$copyModalBody.append('<textarea class="raw"></textarea>');
|
this.$copyModalBody.append('<textarea class="raw"></textarea>');
|
||||||
|
@ -44,9 +44,6 @@
|
||||||
this.$copyModal.modal('show');
|
this.$copyModal.modal('show');
|
||||||
$textarea.select();
|
$textarea.select();
|
||||||
},
|
},
|
||||||
copyClose: function() {
|
|
||||||
$('textarea', this.$copyModal).remove();
|
|
||||||
},
|
|
||||||
copyFromClick: function() {
|
copyFromClick: function() {
|
||||||
this.copy();
|
this.copy();
|
||||||
return false;
|
return false;
|
||||||
|
@ -66,7 +63,7 @@
|
||||||
this.select();
|
this.select();
|
||||||
|
|
||||||
// Local vars
|
// Local vars
|
||||||
var that = this;
|
that = this;
|
||||||
var editPane = this.editTemplate({snipt: this.model.toJSON()});
|
var editPane = this.editTemplate({snipt: this.model.toJSON()});
|
||||||
|
|
||||||
// Init main view
|
// Init main view
|
||||||
|
@ -107,23 +104,21 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
// Edit buttons
|
// Edit buttons
|
||||||
$('button.delete', window.site.$main_edit).on('click', function(e) {
|
$('button.delete', window.site.$main_edit).on('click', function() {
|
||||||
if (confirm('Are you sure you want to delete this snipt?')) {
|
if (confirm('Are you sure you want to delete this snipt?')) {
|
||||||
that.model.destroy();
|
that.model.destroy();
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
window.site.snipt_list.escapeUI(true);
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
$('button.cancel', window.site.$main_edit).on('click', function(e) {
|
$('button.cancel', window.site.$main_edit).on('click', function() {
|
||||||
window.site.snipt_list.escapeUI();
|
window.site.snipt_list.escapeUI();
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
$('button.save', window.site.$main_edit).on('click', function(e) {
|
$('button.save', window.site.$main_edit).on('click', function() {
|
||||||
that.model.set('title', $('input#snipt_title').val());
|
that.save();
|
||||||
that.model.save();
|
|
||||||
|
|
||||||
window.site.snipt_list.escapeUI();
|
window.site.snipt_list.escapeUI();
|
||||||
|
return false;
|
||||||
e.preventDefault();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
window.scrollTo(0, 0);
|
window.scrollTo(0, 0);
|
||||||
|
@ -131,6 +126,8 @@
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
embed: function() {
|
embed: function() {
|
||||||
|
$('textarea', this.$embedModal).remove();
|
||||||
|
|
||||||
window.ui_halted = true;
|
window.ui_halted = true;
|
||||||
|
|
||||||
this.$embedModalBody.append('<textarea class="raw"></textarea>');
|
this.$embedModalBody.append('<textarea class="raw"></textarea>');
|
||||||
|
@ -139,9 +136,6 @@
|
||||||
this.$embedModal.modal('show');
|
this.$embedModal.modal('show');
|
||||||
$textarea.select();
|
$textarea.select();
|
||||||
},
|
},
|
||||||
embedClose: function() {
|
|
||||||
$('textarea', this.$embedModal).remove();
|
|
||||||
},
|
|
||||||
embedFromClick: function() {
|
embedFromClick: function() {
|
||||||
this.embed();
|
this.embed();
|
||||||
return false;
|
return false;
|
||||||
|
@ -152,8 +146,14 @@
|
||||||
this.select();
|
this.select();
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
fadeAndRemove: function() {
|
||||||
|
window.$selected = false;
|
||||||
|
$(this.el).fadeOut('fast', function() {
|
||||||
|
$(this).remove();
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
},
|
||||||
initLocalVars: function() {
|
initLocalVars: function() {
|
||||||
this.$el = $(this.el);
|
|
||||||
this.$aside = $('aside', this.$el);
|
this.$aside = $('aside', this.$el);
|
||||||
this.$container = $('div.container', this.$el);
|
this.$container = $('div.container', this.$el);
|
||||||
|
|
||||||
|
@ -166,12 +166,10 @@
|
||||||
this.$tags = $('section.tags ul', this.$aside);
|
this.$tags = $('section.tags ul', this.$aside);
|
||||||
|
|
||||||
this.$copyModal.on('hidden', function(e) {
|
this.$copyModal.on('hidden', function(e) {
|
||||||
$(this).parent().trigger('copyClose');
|
|
||||||
window.ui_halted = false;
|
window.ui_halted = false;
|
||||||
window.from_modal = true;
|
window.from_modal = true;
|
||||||
});
|
});
|
||||||
this.$embedModal.on('hidden', function(e) {
|
this.$embedModal.on('hidden', function(e) {
|
||||||
$(this).parent().trigger('embedClose');
|
|
||||||
window.ui_halted = false;
|
window.ui_halted = false;
|
||||||
window.from_modal = true;
|
window.from_modal = true;
|
||||||
});
|
});
|
||||||
|
@ -193,11 +191,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
remove: function() {
|
remove: function() {
|
||||||
console.log('remove() on view called');
|
return false;
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
console.log('render called');
|
|
||||||
|
|
||||||
this.$el.html(this.template({
|
this.$el.html(this.template({
|
||||||
snipt: this.model.toJSON()
|
snipt: this.model.toJSON()
|
||||||
}));
|
}));
|
||||||
|
@ -226,6 +222,13 @@
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
save: function() {
|
||||||
|
that.model.set('title', $('input#snipt_title').val());
|
||||||
|
that.model.set('tags', $('label.tags textarea').val());
|
||||||
|
that.model.set('tags_list', $('label.tags textarea').val());
|
||||||
|
|
||||||
|
that.model.save();
|
||||||
|
},
|
||||||
select: function(fromClick) {
|
select: function(fromClick) {
|
||||||
|
|
||||||
$('article.selected', window.site.snipt_list.$el).removeClass('selected');
|
$('article.selected', window.site.snipt_list.$el).removeClass('selected');
|
||||||
|
@ -254,7 +257,6 @@
|
||||||
initialize: function(opts) {
|
initialize: function(opts) {
|
||||||
|
|
||||||
opts.snipts.each(this.addExistingSnipt);
|
opts.snipts.each(this.addExistingSnipt);
|
||||||
this.$el = $(this.el);
|
|
||||||
|
|
||||||
this.keyboardShortcuts();
|
this.keyboardShortcuts();
|
||||||
|
|
||||||
|
@ -318,7 +320,7 @@
|
||||||
model: new Snipt.SniptModel(data)
|
model: new Snipt.SniptModel(data)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
escapeUI: function() {
|
escapeUI: function(destroyed) {
|
||||||
if (window.editing) {
|
if (window.editing) {
|
||||||
if (!window.site.$html.hasClass('detail')) {
|
if (!window.site.$html.hasClass('detail')) {
|
||||||
window.site.$body.removeClass('detail');
|
window.site.$body.removeClass('detail');
|
||||||
|
@ -337,6 +339,10 @@
|
||||||
scrollTop: window.$selected.offset().top - 50
|
scrollTop: window.$selected.offset().top - 50
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (destroyed) {
|
||||||
|
window.$selected.trigger('fadeAndRemove');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!window.ui_halted) {
|
if (!window.ui_halted) {
|
||||||
if ($selected) {
|
if ($selected) {
|
||||||
|
|
|
@ -91,6 +91,7 @@ class PrivateUserResource(ModelResource):
|
||||||
list_allowed_methods = []
|
list_allowed_methods = []
|
||||||
authentication = ApiKeyAuthentication()
|
authentication = ApiKeyAuthentication()
|
||||||
authorization = DjangoAuthorization()
|
authorization = DjangoAuthorization()
|
||||||
|
always_return_data = True
|
||||||
cache = SimpleCache()
|
cache = SimpleCache()
|
||||||
|
|
||||||
def apply_authorization_limits(self, request, object_list):
|
def apply_authorization_limits(self, request, object_list):
|
||||||
|
@ -104,6 +105,7 @@ class PrivateTagResource(ModelResource):
|
||||||
allowed_methods = ['get']
|
allowed_methods = ['get']
|
||||||
authentication = ApiKeyAuthentication()
|
authentication = ApiKeyAuthentication()
|
||||||
authorization = DjangoAuthorization()
|
authorization = DjangoAuthorization()
|
||||||
|
always_return_data = True
|
||||||
cache = SimpleCache()
|
cache = SimpleCache()
|
||||||
|
|
||||||
def dehydrate(self, bundle):
|
def dehydrate(self, bundle):
|
||||||
|
@ -142,6 +144,7 @@ class PrivateSniptResource(ModelResource):
|
||||||
ordering = ['created', 'modified',]
|
ordering = ['created', 'modified',]
|
||||||
# TODO max_limit does not work.
|
# TODO max_limit does not work.
|
||||||
max_limit = 200
|
max_limit = 200
|
||||||
|
always_return_data = True
|
||||||
cache = SimpleCache()
|
cache = SimpleCache()
|
||||||
|
|
||||||
def dehydrate(self, bundle):
|
def dehydrate(self, bundle):
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
{% compress css %}
|
{% compress css %}
|
||||||
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/bootstrap.css" />
|
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/bootstrap.css" />
|
||||||
<link rel="stylesheet" type="text/scss" href="{{ STATIC_URL }}css/style.css" />
|
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/style.css" />
|
||||||
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/themes.css" />
|
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/themes.css" />
|
||||||
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/chosen.css" />
|
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/chosen.css" />
|
||||||
{% endcompress %}
|
{% endcompress %}
|
||||||
|
@ -119,9 +119,11 @@
|
||||||
</div>
|
</div>
|
||||||
{% block aside %}
|
{% block aside %}
|
||||||
<aside class="main">
|
<aside class="main">
|
||||||
<section class="ad coffee">
|
{% if not debug %}
|
||||||
<script type="text/javascript" src="http://adsbycoffee.appspot.com/partner.js?publisher=ag1zfmFkc2J5Y29mZmVlchALEglQdWJsaXNoZXIY-VUM"></script>
|
<section class="ad coffee">
|
||||||
</section>
|
<script type="text/javascript" src="http://adsbycoffee.appspot.com/partner.js?publisher=ag1zfmFkc2J5Y29mZmVlchALEglQdWJsaXNoZXIY-VUM"></script>
|
||||||
|
</section>
|
||||||
|
{% endif %}
|
||||||
{% block tags %}{% endblock %}
|
{% block tags %}{% endblock %}
|
||||||
<nav class="footer">
|
<nav class="footer">
|
||||||
<ul>
|
<ul>
|
||||||
|
|
Loading…
Reference in New Issue