X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/d7faec10cb85ad286673eec266ccc397142bc20c..68fb56484e6c9951549632f498ffb07a6f41149e:/redakcja/static/js/catalogue/book_list.js diff --git a/redakcja/static/js/catalogue/book_list.js b/redakcja/static/js/catalogue/book_list.js index 1ff5f064..4d67ca12 100644 --- a/redakcja/static/js/catalogue/book_list.js +++ b/redakcja/static/js/catalogue/book_list.js @@ -11,45 +11,78 @@ var get_ids = function() { return $.map($("input[name=select_chunk]:checked"), function(ele, idx) { return ele.value; - }).join(); + }).concat( + $.map($("input[name=select_book][data-chunk-id!=]:checked"), function(ele, idx) { + return $(ele).attr("data-chunk-id"); + })).join(); }; + - var set_stage = function(key, opt) { - var stage = $("select[name=stage] option[value!=]").eq(key).val(); - $.post($('input[name=chunk_mass_edit_url]').val(), - { - ids: get_ids(), - stage: stage, - }, - function(data, status) { - location.reload(true); - } - ); + var set_field = function(key, ops) { + var fds = {} + fds.stage = ""; + fds.user = ""; + fds.status = ""; + + 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]); + } + + $.post($("#chunk_mass_edit").attr("action"), + $("#chunk_mass_edit").serialize(), + function(data, status) { + location.reload(true); + } + ); + return true; + + }; + var get_items = function(field) { + var d = {}; + $.each($("select[name="+field+"] option[value!=]"), + function(idx, ele) { + d[field+"_"+idx] = { name: $(ele).text() }; + }); + return d; + }; + + $.contextMenu({ selector: '#file-list', items: { "stage": { name: "Set stage", - items: $.map($("select[name=stage] option[value!=]"), - function(ele, idx) { - return { - name: $(ele).text(), - callback: set_stage, - }; - }), + items: get_items("stage"), + icon: "clock", }, -/* "user": { + "user": { name: "Set user", - - }, - "status": { - name: "Set status", - items: - },*/ - + items: get_items("user"), + icon: "user", + }, + "publish": { + name: "Mark publishable", + icon: "ok", + }, + "unpublish": { + name: "Mark not publishable", + icon: "stop", + }, }, + callback: set_field, }); });