add some support for customizing product options
[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
84e29d01
TC
21<:.define addform_value_entry:>
22<div class="valueentry<:= index mod 2 == 0 ? "" : " odd":>">
23 <span><input type="text" name="value<:= index :>" value="<:= cgi.param("value" _ index) :>" maxlength="255" class="editor_field" title="Enter some values here" /></span>
24 <span><input type="radio" name="default" value="value<:= index :>"></span>
25 <span><:.call "error_img", field: "value" _ index:></span>
26</div>
27<:.end define:>
28<:.define addform_value_head:>
29<div class="valueentry"><span>Values</span><span>Default</span></div>
30<:.end define:>
31<:.define value_entry_menu :>
32<:.if request.user_can("bse_edit_prodopt_edit", article):>
33<div class="valueentrymenu">
34<a href="<:script:>?id=<:= product.id:>&amp;value_id=<:= dboptionvalue.id:>&amp;a_edit_option_value=1">Edit</a>
35<a href="<:script:>?id=<:= product.id:>&amp;value_id=<:= dboptionvalue.id:>&amp;a_confdel_option_value=1">Delete</a>
36<:.call "dboptionvalue_move":>
37<:.end if :>
38</div>
39<:.end define :>
40<:.define value_entry:>
41<div id="valentry<:= dboptionvalue.id:>" class="valueentry<:= loop.index mod 2 == 1 ? " odd" : "":>">
42<span id="prodoptvalue<:= dboptionvalue.id:>"><:= dboptionvalue.value:></span>
43<:.if dboptionvalue.id == dboption.default_value:>(default)<:.end if:>
44<:.call "value_entry_menu":>
45</div>
46<:.end define:>
47<:include admin/edit_prodopt_custom.tmpl optional:>
48
c274a8aa
TC
49<:.set dboptions = [ product.db_options ] :>
50<:.if dboptions.size:>
58baa27b 51<h2>Product options</h2>
c274a8aa 52<:.if request.user_can("bse_edit_prodopt_move", article) :>
4de47893 53<div id="prodoptmenu">All options:
c274a8aa
TC
54<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>
55<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 56<img src="/images/admin/busy.gif" id="busy_img" style="visibility: hidden" alt="busy" />
4de47893 57</div>
c274a8aa
TC
58<:.end if :>
59<div id="productoptions" <:.if request.user_can("bse_edit_prodopt_move", article):>class="moveable"<:.end if:>>
60<:.for dboption in dboptions :>
61<:.set dboloop = loop :>
62<div id="prodopt<:= dboption.id:>" class="prodopt">
63<div id="prodoptmenu<:= dboption.id:>" class="prodoptmenu">Option:<span id="prodoptname<:= dboption.id:>"><:= dboption.name:></span>
1dbed965 64<div class="prodoptmenuoptions">
7ebbfeb9 65<:.if request.user_can("bse_edit_prodopt_edit", article) :>
c274a8aa
TC
66<a id="editoption<:= dboption.id:>" href="<:script:>?id=<:= article.id:>&amp;a_edit_option=1&amp;option_id=<:= dboption.id:>">Edit</a>
67<a href="<:script:>?id=<:= article.id:>&amp;a_delconf_option=1&amp;option_id=<:= dboption.id:>">Delete</a>
68<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>
69<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>
70<:.end if :>
71<:.if request.user_can("bse_edit_prodopt_move", article) :><:.call "dboption_move", loop: dboloop:><:.end if:>
4de47893 72</div>
1dbed965 73</div>
c274a8aa
TC
74<div id="vallist<:= dboption.id:>" class="prodoptvalues">
75<:.for dboptionvalue in [ dboption.values ] :>
76<:.set dbovloop = loop :>
84e29d01 77<:.call "value_entry", "loop":dbovloop:>
c274a8aa 78<:.end for :>
5f3a2963 79</div>
c274a8aa 80<:.if request.user_can("bse_edit_prodopt_edit", article) :>
5f3a2963 81<div class="addvalueform">
c274a8aa 82<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 83</div>
c274a8aa 84<:.end if :>
58baa27b 85</div>
c274a8aa 86<:.end for :>
58baa27b 87</div>
c274a8aa
TC
88<:.end if:>
89<:.if request.user_can("bse_edit_prodopt_add", article) :>
8f786525 90<div id="addoptionform" class="prodopt">
58baa27b
TC
91<form action="<:script:>" method="post">
92<:csrfp admin_add_option hidden:>
93<input type="hidden" name="_t" value="prodopts" />
c274a8aa
TC
94<input type="hidden" name="id" value="<:= article.id:>" />
95<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 96<div class="prodoptvalues">
abcd71ea
TC
97<:.call "addform_value_head":>
98<:.for index in [ 1 .. 5 ] :>
99<:.call "addform_value_entry" :>
100<:.end for:>
8f786525 101</div>
70b17b6f 102</form>
58baa27b
TC
103</div>
104<div id="addoptionbutton" style="display: none">
105<a href="#" onclick="javascript: document.getElementById('addoptionform').style.display='block'; return false;">Add an option</a>
106</div>
c274a8aa 107<:.end if :>
8a3b8db8 108<script type="text/javascript">
58baa27b 109
c274a8aa 110var prodopts = <:= bse.json(dboptions.map(@{o: o.data_only })) |raw:>;
58baa27b
TC
111var reorder_values_csrf = '<:csrfp admin_move_option_value:>';
112var reorder_options_csrf = '<:csrfp admin_move_option:>';
5708b3ac 113var edit_option_csrf = '<:csrfp admin_save_option:>';
1660ce30 114var edit_value_csrf = '<:csrfp admin_save_option_value:>';
c274a8aa 115var article_id = "<:= article.id:>";
4de47893 116var edit_script = "<:script:>";
58baa27b 117
c274a8aa
TC
118var user_can_edit_option = <:= request.user_can("bse_edit_prodopt_edit", article) ? "true" : "false":>;
119var user_can_delete_option = <:= request.user_can("bse_edit_prodopt_delete", article) ? "true" : "false" :>;
120var user_can_move_option = <:= request.user_can("bse_edit_prodopt_move", article) ? "true" : "false" :>;
58baa27b 121
c274a8aa 122var show_add_form = <:= cgi.param("a_add_option") ? "true" : "false" :>;
5f3a2963 123
58baa27b 124</script>