makr publoshable / not publishable
authorMarcin Koziej <marcin@lolownia.org>
Thu, 10 May 2012 12:46:13 +0000 (14:46 +0200)
committerMarcin Koziej <marcin@lolownia.org>
Thu, 10 May 2012 12:46:13 +0000 (14:46 +0200)
apps/catalogue/views.py
redakcja/static/js/catalogue/book_list.js

index 16d1174..657a125 100644 (file)
@@ -414,6 +414,21 @@ def chunk_mass_edit(request):
                 
             for c in chunks: c.user = user
 
                 
             for c in chunks: c.user = user
 
+        status = request.POST.get('status')
+        if status:
+            books_affected = set()
+            for c in chunks:
+                if status == 'publish':
+                    c.head.publishable = True
+                    c.head.save()
+                elif status == 'unpublish':
+                    c.head.publishable = False
+                    c.head.save()
+                c.touch()  # cache
+                books_affected.add(c.book)
+            for b in books_affected:
+                b.touch()  # cache
+
         for c in chunks: c.save()
 
         return HttpResponse("", content_type="text/plain")
         for c in chunks: c.save()
 
         return HttpResponse("", content_type="text/plain")
index 96809b6..d7256d3 100644 (file)
     
 
        var set_field = function(key, ops) {
     
 
        var set_field = function(key, ops) {
-           var kp = key.split('_');
-           var field = kp[0];
-           var idx = parseInt(kp[1]);
-
             var fds = {}
             fds.stage = "";
             fds.user = "";
             fds.status = "";
             var fds = {}
             fds.stage = "";
             fds.user = "";
             fds.status = "";
-           fds[field] = $("select[name="+field+"] option[value!=]").eq(idx).val();
+
+           if (key == "publish" || key == "unpublish") {
+               fds["status"] = key;
+           } else {
+               var kp = key.split('_');
+               var field = kp[0];
+               var idx = parseInt(kp[1]);
+
+               fds[field] = $("select[name="+field+"] option[value!=]").eq(idx).val();
+           }
+           /* fill in the form */
             $("#chunk_mass_edit [name=ids]").val(get_ids());
             for (var fn in fds) {
                 $("#chunk_mass_edit [name="+fn+"]").val(fds[fn]);
             $("#chunk_mass_edit [name=ids]").val(get_ids());
             for (var fn in fds) {
                 $("#chunk_mass_edit [name="+fn+"]").val(fds[fn]);
                    name: "Set user",
                     items: get_items("user"),
                 },
                    name: "Set user",
                     items: get_items("user"),
                 },
-                "status": {
-                    name: "set status",
-                    items: get_items("status"),
+                "publish": {
+                    name: "Mark publishable",
                 },
                 },
+               "unpublish": {
+                   name: "Mark not publishable",
+               },
            },
            callback: set_field,
        });
            },
            callback: set_field,
        });