modernize edit_prodopts.tmpl
[bse.git] / site / templates / admin / edit_prodopts.tmpl
CommitLineData
8a3b8db8 1<:wrap admin/base.tmpl title=>[cat "Options for product: " [article title]], showtitle=>1, menuitem=>prodopts, js=>"admin_prodopts.js":>
58baa27b
TC
2<:ifMessage:><div id="message"><:message:></div><:or:><:eif:>
3<:include admin/product_menu.tmpl:>
4
c274a8aa
TC
5<:.define dboption_move:>
6<:# parameters: loop -:>
7<:.set baseurl = "/cgi-bin/admin/add.pl?id=" _ article.id _ "&option_id=" _ loop.current.id _ "&_csrfp=" _ request.get_csrf_token("admin_move_option") _ "&_t=" _ cgi.param("_t") _ "&" :>
8<:.set upurl = loop.is_first ? "" : baseurl _ "a_option_moveup=1" :>
9<:.set downurl = loop.is_last ? "" : baseurl _ "a_option_movedown=1" :>
10<span id="prodoptmove<:= loop.current.id :>"><:.call "make_arrows", down_url: downurl, up_url: upurl :></span>
11<:.end define :>
12
13<:.define dboptionvalue_move:>
14<:# parameters: loop -:>
15<:.set baseurl = "/cgi-bin/admin/add.pl?id=" _ article.id _ "&value_id=" _ loop.current.id _ "&_csrfp=" _ request.get_csrf_token("admin_move_option_value") _ "&_t=" _ cgi.param("_t") _ "&" :>
16<:.set upurl = loop.is_first ? "" : baseurl _ "a_option_value_moveup=1" :>
17<:.set downurl = loop.is_last ? "" : baseurl _ "a_option_value_movedown=1" :>
18<span id="prodoptvaluemove<:= loop.current.id :>"><:.call "make_arrows", down_url: downurl, up_url: upurl :></span>
19<:.end define :>
20
21<:.set dboptions = [ product.db_options ] :>
22<:.if dboptions.size:>
58baa27b 23<h2>Product options</h2>
c274a8aa 24<:.if request.user_can("bse_edit_prodopt_move", article) :>
4de47893 25<div id="prodoptmenu">All options:
c274a8aa
TC
26<a id="sortoptions" href="<:script:>?a_option_reorder=1&amp;_t=prodopts&amp;id=<:= article.id:>&amp;_csrfp=<:csrfp admin_move_option:>&amp;option_ids=<:= dboptions.sort(@{a,b: a.lc cmp b.lc }).map(@{o: o.id }).join(",") :>">Sort</a>
27<a id="reverseoptions" href="<:script:>?a_option_reorder=1&amp;_t=prodopts&amp;id=<:article id:>&amp;_csrfp=<:csrfp admin_move_option:>&amp;option_ids=<:= dboptions.reverse.map(@{o: o.id}).join(","):>">Reverse</a>
8a3b8db8 28<img src="/images/admin/busy.gif" id="busy_img" style="visibility: hidden" alt="busy" />
4de47893 29</div>
c274a8aa
TC
30<:.end if :>
31<div id="productoptions" <:.if request.user_can("bse_edit_prodopt_move", article):>class="moveable"<:.end if:>>
32<:.for dboption in dboptions :>
33<:.set dboloop = loop :>
34<div id="prodopt<:= dboption.id:>" class="prodopt">
35<div id="prodoptmenu<:= dboption.id:>" class="prodoptmenu">Option:<span id="prodoptname<:= dboption.id:>"><:= dboption.name:></span>
1dbed965 36<div class="prodoptmenuoptions">
c274a8aa
TC
37<:.if request.user_can("bse_edit_prodopt_edit", "article") :>
38<a id="editoption<:= dboption.id:>" href="<:script:>?id=<:= article.id:>&amp;a_edit_option=1&amp;option_id=<:= dboption.id:>">Edit</a>
39<a href="<:script:>?id=<:= article.id:>&amp;a_delconf_option=1&amp;option_id=<:= dboption.id:>">Delete</a>
40<a id="sortvals<:= dboption.id:>" href="<:script:>?id=<:article id:>&amp;a_option_value_reorder=1&amp;option_id=<:= dboption.id:>&amp;_csrfp=<:csrfp admin_move_option_value:>&amp;_t=prodopts&amp;value_ids=<:= dboptions.sort(@{a,b: a.lc cmp b.lc }).map(@{o: o.id }).join(",") :>">Sort</a>
41<a id="reversevals<:= dboption.id:>" href="<:script:>?id=<:= article.id:>&amp;a_option_value_reorder=1&amp;option_id=<:= dboption.id:>&amp;_csrfp=<:csrfp admin_move_option_value:>&amp;_t=prodopts&amp;value_ids=<:= dboptions.reverse.map(@{o: o.id}).join(",") :>">Reverse</a>
42<:.end if :>
43<:.if request.user_can("bse_edit_prodopt_move", article) :><:.call "dboption_move", loop: dboloop:><:.end if:>
4de47893 44</div>
1dbed965 45</div>
c274a8aa
TC
46<div id="vallist<:= dboption.id:>" class="prodoptvalues">
47<:.for dboptionvalue in [ dboption.values ] :>
48<:.set dbovloop = loop :>
49<div id="valentry<:= dboptionvalue.id:>" class="valueentry<:= dbovloop.index mod 2 == 1 ? " odd" : "":>"><span id="prodoptvalue<:= dboptionvalue.id:>"><:= dboptionvalue.value:></span>
50<:.if dboptionvalue.id == dboption.default_value:>(default)<:.end if:>
51<:.if request.user_can("bse_edit_prodopt_edit", article):>
5f3a2963 52<div class="valueentrymenu">
c274a8aa
TC
53<a href="<:script:>?id=<:= product.id:>&amp;value_id=<:= dboptionvalue.id:>&amp;a_edit_option_value=1">Edit</a>
54<a href="<:script:>?id=<:= product.id:>&amp;value_id=<:= dboptionvalue.id:>&amp;a_confdel_option_value=1">Delete</a>
55<:.call "dboptionvalue_move", loop:dbovloop:>
5f3a2963 56</div>
c274a8aa 57<:.end if :>
5f3a2963 58</div>
c274a8aa 59<:.end for :>
5f3a2963 60</div>
c274a8aa 61<:.if request.user_can("bse_edit_prodopt_edit", article) :>
5f3a2963 62<div class="addvalueform">
c274a8aa 63<form action="<:script:>" method="post" id="valform<:= dboption.id:>" class="addvalue"><input type="hidden" name="id" value="<:= article.id:>" /><input type="hidden" name="option_id" value="<:= dboption.id:>" /><input type="hidden" name="_t" value="prodopts" /><:csrfp admin_add_option_value hidden:><input type="text" name="value" class="add_field" /><input type="submit" name="a_add_option_value" value="Add Value" class="add_submit" /></form>
5f3a2963 64</div>
c274a8aa 65<:.end if :>
58baa27b 66</div>
c274a8aa 67<:.end for :>
58baa27b 68</div>
c274a8aa
TC
69<:.end if:>
70<:.if request.user_can("bse_edit_prodopt_add", article) :>
8f786525 71<div id="addoptionform" class="prodopt">
58baa27b
TC
72<form action="<:script:>" method="post">
73<:csrfp admin_add_option hidden:>
74<input type="hidden" name="_t" value="prodopts" />
c274a8aa
TC
75<input type="hidden" name="id" value="<:= article.id:>" />
76<div class="prodoptmenu">Option: <input type="text" name="name" value="<:= cgi.param("name") :>" maxlength="255" class="editor_field" title="Enter the name of your new option here" /><:.call "error_img", field: "name":><input type="submit" name="a_add_option" value="Add New Option" class="editor_ok_button" /></div>
8f786525 77<div class="prodoptvalues">
c274a8aa
TC
78<div class="valueentry"><input type="text" name="value1" value="<:= cgi.param("value1") :>" maxlength="255" class="editor_field" title="Enter some values here" /><:.call "error_img", field: "value1":></div>
79<div class="valueentry odd"><input type="text" name="value2" value="<:= cgi.param("value2") :>" maxlength="255" class="editor_field" /><:.call "error_img", field: "value2":></div>
80<div class="valueentry"><input type="text" name="value3" value="<:= cgi.param("value3") :>" maxlength="255" class="editor_field" /><:.call "error_img", field: "value3" :></div>
81<div class="valueentry odd"><input type="text" name="value4" value="<:= cgi.param("value4") :>" maxlength="255" class="editor_field" /><:.call "error_img", field: "value4":></div>
82<div class="valueentry"><input type="text" name="value5" value="<:= cgi.param("value5") :>" maxlength="255" class="editor_field" /><:.call "error_img", field: "value5":></div>
8f786525 83</div>
70b17b6f 84</form>
58baa27b
TC
85</div>
86<div id="addoptionbutton" style="display: none">
87<a href="#" onclick="javascript: document.getElementById('addoptionform').style.display='block'; return false;">Add an option</a>
88</div>
c274a8aa 89<:.end if :>
8a3b8db8 90<script type="text/javascript">
58baa27b 91
c274a8aa 92var prodopts = <:= bse.json(dboptions.map(@{o: o.data_only })) |raw:>;
58baa27b
TC
93var reorder_values_csrf = '<:csrfp admin_move_option_value:>';
94var reorder_options_csrf = '<:csrfp admin_move_option:>';
5708b3ac 95var edit_option_csrf = '<:csrfp admin_save_option:>';
1660ce30 96var edit_value_csrf = '<:csrfp admin_save_option_value:>';
c274a8aa 97var article_id = "<:= article.id:>";
4de47893 98var edit_script = "<:script:>";
58baa27b 99
c274a8aa
TC
100var user_can_edit_option = <:= request.user_can("bse_edit_prodopt_edit", article) ? "true" : "false":>;
101var user_can_delete_option = <:= request.user_can("bse_edit_prodopt_delete", article) ? "true" : "false" :>;
102var user_can_move_option = <:= request.user_can("bse_edit_prodopt_move", article) ? "true" : "false" :>;
58baa27b 103
c274a8aa 104var show_add_form = <:= cgi.param("a_add_option") ? "true" : "false" :>;
5f3a2963 105
58baa27b 106</script>