re-ordering and deleting pages has landed
This commit is contained in:
parent
c8250a6f70
commit
ee4b290770
|
@ -353,10 +353,12 @@ class Page(models.Model):
|
|||
Use this function to set a new page no. on a Page instance. Changes page numbers of other pages in article accordingly.
|
||||
"""
|
||||
old_page_no = self.page_no
|
||||
new_page_no = int(new_page_no)
|
||||
self.page_no = new_page_no
|
||||
self.save()
|
||||
if new_page_no < old_page_no:
|
||||
pages_after = Page.objects.filter(article=self.article, page_no__gte=new_page_no).filter(page_no__lt=old_page_no).exclude(pk=self.id)
|
||||
# print "AAAAAAAAAAAAA" + str(pages_after.count())
|
||||
for a in pages_after:
|
||||
a.page_no = a.page_no + 1
|
||||
a.save()
|
||||
|
|
|
@ -5,6 +5,8 @@ urlpatterns = patterns('',
|
|||
(r'^editor/$', views.editor),
|
||||
(r'^upload/$', views.upload),
|
||||
(r'^new_page/', views.new_page),
|
||||
(r'^delete_page/', views.delete_page),
|
||||
(r'^move_page/', views.move_page),
|
||||
(r'^article/json/', views.article_json),
|
||||
(r'^textbox/new/', views.textbox_new),
|
||||
(r'^textbox/update_css/', views.textbox_update_css),
|
||||
|
|
|
@ -664,7 +664,7 @@ def new_page(request):
|
|||
p = Page()
|
||||
p.article = article
|
||||
try:
|
||||
last_page = Page.objects.filter(article=article).order_by('-page_no')[0:1]
|
||||
last_page = Page.objects.filter(article=article).order_by('-page_no')[0]
|
||||
last_page_no = last_page.page_no
|
||||
except:
|
||||
last_page_no = 0
|
||||
|
@ -689,6 +689,7 @@ def new_page(request):
|
|||
@login_required_json
|
||||
def delete_page(request):
|
||||
page = get_object_or_404_json(Page, id=request.GET['id'])
|
||||
page_id = page.id
|
||||
page.delete()
|
||||
rev_id = saveRevision({
|
||||
'user': request.user,
|
||||
|
@ -696,7 +697,7 @@ def delete_page(request):
|
|||
'box_type': 'page',
|
||||
'prop': 'delete_page',
|
||||
'old_val': page.get_dict(1),
|
||||
'new_val': '',
|
||||
'new_val': page_id,
|
||||
'uuid': request.GET['uuid']
|
||||
})
|
||||
r = {
|
||||
|
@ -704,6 +705,29 @@ def delete_page(request):
|
|||
}
|
||||
return HttpResponse(json.dumps(r), mimetype="application/json")
|
||||
|
||||
|
||||
@login_required_json
|
||||
def move_page(request):
|
||||
page = get_object_or_404_json(Page, id=request.GET['id'])
|
||||
current_no = page.page_no
|
||||
new_no = request.GET['new_order']
|
||||
page.set_page_no(new_no)
|
||||
rev_id = saveRevision({
|
||||
'user': request.user,
|
||||
'page_id': page.id,
|
||||
'box_id': page.id,
|
||||
'box_type': 'page',
|
||||
'prop': 'move_page',
|
||||
'old_val': current_no,
|
||||
'new_val': new_no,
|
||||
'uuid': request.GET['uuid']
|
||||
})
|
||||
r = {
|
||||
'rev_id': rev_id
|
||||
}
|
||||
return HttpResponse(json.dumps(r), mimetype="application/json")
|
||||
|
||||
|
||||
def product_list(request):
|
||||
products = Product.objects.all()
|
||||
return render_to_response("product_list.html", {'products': products})
|
||||
|
|
|
@ -188,3 +188,22 @@ def add(request):
|
|||
#no upload
|
||||
return HttpResponseRedirect('/')
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@login_required
|
||||
def editFile(request):
|
||||
errors = []
|
||||
try:
|
||||
id = request.POST['id']
|
||||
fil = File.objects.get(pk=id)
|
||||
except:
|
||||
errors.append("Invalid File ID")
|
||||
keys = ['title', 'description', 'tags']
|
||||
for k in keys:
|
||||
val = request.POST[k]
|
||||
fil.__setattr__(k, val)
|
||||
fil.save()
|
||||
response = {
|
||||
'errors': errors
|
||||
}
|
||||
return render_to_json_response(response)
|
||||
|
|
|
@ -78,6 +78,17 @@ function handleRevision(json) {
|
|||
new Canvas({}, j);
|
||||
break;
|
||||
|
||||
case "move_page":
|
||||
var page_id = json.box_id;
|
||||
var c = getCanvasById(page_id);
|
||||
c.movePage(json.new_val - 1, true);
|
||||
break;
|
||||
|
||||
case "delete_page":
|
||||
var c = getCanvasById(json.new_val);
|
||||
c.deleteme(true);
|
||||
break;
|
||||
|
||||
case "new_box":
|
||||
if (json.box_type == 'image') {
|
||||
var j = JSON.parse(json.new_val);
|
||||
|
@ -398,6 +409,66 @@ Canvas.prototype.appendBox = function(box) {
|
|||
return this;
|
||||
}
|
||||
|
||||
Canvas.prototype.movePage = function(newOrder, dontSave) {
|
||||
var that = this;
|
||||
if (typeof(dontSave) === 'undefined') {
|
||||
dontSave = false;
|
||||
}
|
||||
var currentIndex = this.jq.index('.canvas');
|
||||
if (newOrder == 0) {
|
||||
this.jq.remove().insertBefore($('.canvas').eq(0));
|
||||
} else if (newOrder < currentIndex) {
|
||||
var prevCanvas = $('.canvas').eq(newOrder - 1);
|
||||
this.jq.remove().insertAfter(prevCanvas);
|
||||
} else {
|
||||
var prevCanvas = $('.canvas').eq(newOrder);
|
||||
this.jq.remove().insertAfter(prevCanvas);
|
||||
}
|
||||
reorderEdgeArticle();
|
||||
if (!dontSave) {
|
||||
var url = "/edit/move_page/";
|
||||
$.getJSON(url, {
|
||||
'id': that.id,
|
||||
'new_order': newOrder + 1,
|
||||
'uuid': UUID
|
||||
}, function(response) {
|
||||
// console.log(response);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Canvas.prototype.deleteme = function(dontSave) {
|
||||
var that = this;
|
||||
this.jq.remove();
|
||||
edgeArticle.splice(that.index,1);
|
||||
reorderEdgeArticle();
|
||||
if (typeof(dontSave) == 'undefined') {
|
||||
dontSave = false;
|
||||
}
|
||||
if (!dontSave) {
|
||||
var url = "/edit/delete_page/";
|
||||
$.getJSON(url, {
|
||||
'id': that.id
|
||||
}, function(response) {
|
||||
// console.log(response);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function reorderEdgeArticle() {
|
||||
edgeArticle.sort(function(a,b) {
|
||||
var aIndex = a.jq.index('.canvas');
|
||||
var bIndex = b.jq.index('.canvas');
|
||||
return aIndex - bIndex;
|
||||
});
|
||||
$('.canvas').each(function() {
|
||||
var thisIndex = $(this).index('.canvas');
|
||||
$(this).attr("data-index", thisIndex);
|
||||
var c = $(this).children().eq(0).getCanvas();
|
||||
c.index = thisIndex;
|
||||
});
|
||||
}
|
||||
|
||||
function getHighestIndex(canvas) {
|
||||
page_boxes = canvas.find('.box');
|
||||
if (page_boxes.length == 0) {
|
||||
|
@ -1683,4 +1754,30 @@ $('.toggle_handle').live("click", function() {
|
|||
page.find('.ruler').each(function() {
|
||||
if ($(this).is(":visible")) { $(this).fadeOut("fast"); } else { $(this).fadeIn("fast"); };
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
$('.delete_page').live("click", function(e) {
|
||||
var canvas = $(this).getCanvas();
|
||||
if (confirm("Are you sure you want to delete this page?")) {
|
||||
canvas.deleteme();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$('.move_page_up').live("click", function(e) {
|
||||
var canvas = $(this).getCanvas();
|
||||
var currIndex = canvas.jq.index(".canvas");
|
||||
if (currIndex == 0) {
|
||||
return false;
|
||||
}
|
||||
var newIndex = currIndex - 1;
|
||||
canvas.movePage(newIndex);
|
||||
});
|
||||
|
||||
$('.move_page_down').live("click", function(e) {
|
||||
var canvas = $(this).getCanvas();
|
||||
var currIndex = canvas.jq.index(".canvas");
|
||||
var newIndex = currIndex + 1;
|
||||
canvas.movePage(newIndex);
|
||||
});
|
||||
|
|
|
@ -305,97 +305,3 @@ $(document).ready(function() {
|
|||
}
|
||||
});
|
||||
|
||||
function doProgress(progress) {
|
||||
//do something with status and progress, i.e. set progressbar width:
|
||||
$('#progress').css('width', parseInt(progress*100, 10) +'%');
|
||||
$('#progressstatus').html(parseInt(progress*100, 10) + '% - ' + ogg.status);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var UploadQueue = function() {
|
||||
var that = this;
|
||||
this.allFiles = [];
|
||||
this.isUploading = false;
|
||||
this.$list = $('#filesList');
|
||||
this.$progress = $('#progressbar');
|
||||
this.len = function() {
|
||||
return this.allFiles.length;
|
||||
};
|
||||
this.getLi = function(no) {
|
||||
return this.$list.children('li').eq(no);
|
||||
}
|
||||
this.init();
|
||||
}
|
||||
|
||||
UploadQueue.prototype.init = function() {
|
||||
// $('#progressbar').show();
|
||||
$('#progressbar').width(200);
|
||||
// $('#progressbar').css('background-color', '#80ADB0');
|
||||
$('#progressbar').html('<div id="progress" style="height:20px;width:0%" /><div id="progressstatus" style="">uploading</div>');
|
||||
}
|
||||
|
||||
/* param f = file */
|
||||
UploadQueue.prototype.getData = function(f) {
|
||||
return {
|
||||
'firefogg': 1,
|
||||
'name': f.name,
|
||||
'category': $('#files_category').val()
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
UploadQueue.prototype.uploadNext = function() {
|
||||
|
||||
};
|
||||
|
||||
|
||||
UploadQueue.prototype.addFile = function(f) {
|
||||
for (var i=0; i<this.len(); i++) {
|
||||
if (this.allFiles[i].name == f.name) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
this.allFiles.push(f);
|
||||
this.addFileToList(f);
|
||||
// this.$list.triggerEvent("fileAdded");
|
||||
if (!this.isUploading) {
|
||||
this.upload(this.len() - 1);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
UploadQueue.prototype.addFileToList = function(f) {
|
||||
var that = this;
|
||||
var $li = $('<li />').data("file", f).text(f.name).appendTo(that.$list);
|
||||
};
|
||||
|
||||
UploadQueue.prototype.markDone = function(no) {
|
||||
$('.uploading').removeClass("uploading");
|
||||
this.getLi(no).addClass("uploaded");
|
||||
if (this.len() > (no + 1)) {
|
||||
this.upload(no + 1);
|
||||
} else {
|
||||
this.isUploading = false;
|
||||
$('#progressbar').hide();
|
||||
}
|
||||
};
|
||||
|
||||
UploadQueue.prototype.upload = function(no) {
|
||||
var that = this;
|
||||
var fil = this.allFiles[no];
|
||||
// console.log("uploading", fil);
|
||||
var data = this.getData(fil);
|
||||
var $li = this.getLi(no);
|
||||
this.isUploading = true;
|
||||
$('#progressbar').show();
|
||||
$li.addClass("uploading");
|
||||
ogg = FirefoggUploader(fil, add_url, data, function(ogg) {
|
||||
if (ogg.resultUrl) {
|
||||
that.markDone(no);
|
||||
} else {
|
||||
$('#progressbar').html(ogg.status);
|
||||
}
|
||||
}, doProgress);
|
||||
};
|
||||
|
|
|
@ -74,6 +74,15 @@
|
|||
<script type="text/html" id="tmpl_canvas">
|
||||
<div id="canvas<%= index %>" class="canvas" data-index="<%= index %>">
|
||||
<div class="page_btns">
|
||||
<div class="delete_page page_btn">
|
||||
Delete Page
|
||||
</div>
|
||||
<div class="move_page_up page_btn">
|
||||
Move Page Up
|
||||
</div>
|
||||
<div class="move_page_down page_btn">
|
||||
Move Page Down
|
||||
</div>
|
||||
<div class="toggle_handle page_btn">
|
||||
Toggle Handle
|
||||
</div>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<script type="text/javascript" src="/static/js/upload/progressbar.js"></script>
|
||||
<!-- <script type="text/javascript" src="/static/js/upload/firefogg.js"></script> -->
|
||||
<script type="text/javascript" src="/static/js/upload/upload.js"></script>
|
||||
|
||||
<script type="text/javascript" src="/static/js/upload/edgeUpload.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
var add_url = "/files/add"
|
||||
|
@ -80,7 +80,7 @@ $(function() {
|
|||
background-color: #80ADB0;
|
||||
}
|
||||
|
||||
#progressstatus {
|
||||
#progress {
|
||||
background-color: #005740;
|
||||
}
|
||||
|
||||
|
|
11
edgware/utils/fix_pages.py
Normal file
11
edgware/utils/fix_pages.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from edgware.editor.models import *
|
||||
|
||||
def do():
|
||||
for a in Article.objects.all():
|
||||
pages = a.page_set.all().order_by('page_no')
|
||||
x = 1
|
||||
for p in pages:
|
||||
p.page_no = x
|
||||
p.save()
|
||||
x = x + 1
|
||||
|
Loading…
Reference in New Issue
Block a user