editSuccess.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <?php use_javascript('dd/coordinates.js') ?>
  2. <?php use_javascript('dd/drag.js') ?>
  3. <?php use_javascript('dd/dragdrop.js') ?>
  4. <?php use_stylesheet('dd/lists.css') ?>
  5. <?php $katao_period = $form->getObject() ?>
  6. <div class="content-add01">
  7. <div class="heading01"><h1><?php echo $katao_period->isNew() ? 'Ajout' : 'Modification' ?> d'une période</h1></div>
  8. </div>
  9. <form action="<?php echo url_for('kataoPeriod/update' . (!$katao_period->isNew() ? '?id=' . $katao_period->getId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
  10. <table>
  11. <tfoot>
  12. <tr>
  13. <td colspan="2">
  14. <br /><?php echo submit_tag('Sauver', array('onclick' => 'getSort();')) ?> ou <a href="<?php echo url_for('kataoPeriod/index') ?>">annuler</a>
  15. </td>
  16. </tr>
  17. </tfoot>
  18. <tbody>
  19. <?php echo $form->renderGlobalErrors() ?>
  20. <tr valign="top">
  21. <th align="left"><?php echo $form['name']->renderLabel() ?></th>
  22. <td>
  23. <?php echo $form['name'] ?>
  24. <?php echo $form['name']->renderError() ?>
  25. </td>
  26. </tr>
  27. <tr valign="top">
  28. <th align="left"><?php echo $form['begin_at']->renderLabel() ?></th>
  29. <td>
  30. <?php echo $form['begin_at'] ?>
  31. <?php echo $form['begin_at']->renderError() ?>
  32. </td>
  33. </tr>
  34. <tr valign="top">
  35. <th align="left"><?php echo $form['order_ended_at']->renderLabel() ?></th>
  36. <td>
  37. <?php echo $form['order_ended_at'] ?> <i>(inclus)</i>
  38. <?php echo $form['order_ended_at']->renderError() ?>
  39. </td>
  40. </tr>
  41. <tr valign="top">
  42. <th align="left"><?php echo $form['finish_at']->renderLabel() ?></th>
  43. <td>
  44. <?php echo $form['finish_at'] ?> <i>(inclus)</i>
  45. <?php echo $form['finish_at']->renderError() ?>
  46. <?php echo $form['id'] ?>
  47. </td>
  48. </tr>
  49. </tbody>
  50. </table>
  51. <br />
  52. <div class="content-add01">
  53. <div class="heading01"><h1>Choix des fournisseurs/produits disponibles</h1></div>
  54. </div>
  55. <p>
  56. Faites glisser les fournisseurs disponibles dans les listes suivantes :
  57. <ul>
  58. <li><u>Tous les produits</u> si vous souhaitez activer tous les produits</li>
  59. <li><u>Certains produits</u> si vous ne souhaitez activer que certains produits</li>
  60. </ul>
  61. </p>
  62. <?php echo input_hidden_tag('id', $katao_period->getId()) ?>
  63. <?php echo input_hidden_tag('suppliers_with_all_products', '') ?>
  64. <table cellpadding="0" border="0">
  65. <tr valign="top">
  66. <td rowspan="3">
  67. <div class="section-title-filter4"><b>Fournisseurs :</b></div>
  68. <div class="section-container-filter4">
  69. <ul id="left_col" class="sortable boxy" style="min-height: 250px">
  70. <?php foreach ($katao_suppliers['not_select'] as $id => $name): ?>
  71. <li id="supplier-<?php echo $id ?>" onmouseup="refreshProducts(this)"><?php echo $name ?></li>
  72. <?php endforeach ?>
  73. </ul>
  74. </div>
  75. </td>
  76. <td>&nbsp;&nbsp;</td>
  77. <td>
  78. <table cellpadding="0" border="0">
  79. <tr valign="top">
  80. <td>
  81. <div class="section-title-filter4"><b>Tous les produits :</b></div>
  82. <div class="section-container-filter4">
  83. <ul id="middle_col" class="sortable boxy boxy-large" style="min-height: 150px">
  84. <?php foreach ($katao_suppliers['all_product'] as $id => $name): ?>
  85. <li id="all-products-<?php echo $id ?>" onmouseup="refreshProducts(this)"><?php echo $name ?></li>
  86. <?php endforeach ?>
  87. </ul>
  88. </div>
  89. </td>
  90. </tr>
  91. <tr><td>&nbsp;</td></tr>
  92. <tr valign="top">
  93. <td>
  94. <div class="section-title-filter4"><b>Certains produits :</b> <em>(choisir dans la liste ci-dessous)</em></div>
  95. <div class="section-container-filter4">
  96. <ul id="right_col" class="sortable boxy boxy-large" style="min-height: 150px">
  97. <?php foreach ($katao_suppliers['some_product'] as $id => $name): ?>
  98. <li id="products-<?php echo $id ?>" onmouseup="refreshProducts(this)"><?php echo $name ?></li>
  99. <?php endforeach ?>
  100. </ul>
  101. </div>
  102. </td>
  103. </tr>
  104. <tr valign="top">
  105. <td>
  106. <b>Produits sélectionnés :</b>
  107. </td>
  108. </tr>
  109. <tr valign="top">
  110. <td id="dynamic_product">
  111. <?php echo select_tag('products', options_for_select($products['list'], $products['selected']), array('multiple' => 'multiple', 'style' => 'width:365px;')) ?>
  112. </td>
  113. </tr>
  114. </table>
  115. </td>
  116. </tr>
  117. </table>
  118. <br />
  119. <?php echo submit_tag('Sauver', array('onclick' => 'getSort();')) ?> ou <a href="<?php echo url_for('kataoPeriod/index') ?>">annuler</a>
  120. </form>
  121. <script type="text/javascript" language="JavaScript">
  122. /* <![CDATA[ */
  123. all_supplier = new Array();
  124. <?php if(!empty($katao_suppliers['all']) && is_array($katao_suppliers['all']) && 0 < count($katao_suppliers['all'])) : ?>
  125. <?php foreach($katao_suppliers['all'] as $name) : ?>
  126. all_supplier.push('<?php echo $name ?>');
  127. <?php endforeach ?>
  128. <?php endif ?>
  129. function in_array(needle, haystack, argStrict) {
  130. // http://kevin.vanzonneveld.net
  131. var key = '', strict = !!argStrict;
  132. if (strict) {
  133. for (key in haystack) {
  134. if (haystack[key] === needle) {
  135. return true;
  136. }
  137. }
  138. } else {
  139. for (key in haystack) {
  140. if (haystack[key] == needle) {
  141. return true;
  142. }
  143. }
  144. }
  145. return false;
  146. }
  147. window.onload = function() {
  148. list = document.getElementById("left_col");
  149. DragDrop.makeListContainer( list, 'g1' );
  150. list.onDragOver = function() { this.style["background"] = "#eff3fc"; };
  151. list.onDragOut = function() {this.style["background"] = "none"; };
  152. list = document.getElementById("middle_col");
  153. DragDrop.makeListContainer( list, 'g1' );
  154. list.onDragOver = function() { this.style["background"] = "#eff3fc"; };
  155. list.onDragOut = function() {this.style["background"] = "none"; };
  156. list = document.getElementById("right_col");
  157. DragDrop.makeListContainer( list, 'g1' );
  158. list.onDragOver = function() { this.style["background"] = "#eff3fc"; };
  159. list.onDragOut = function() {this.style["background"] = "none"; };
  160. };
  161. function getSort() {
  162. $("suppliers_with_all_products").value = DragDrop.serData('g1', null);
  163. }
  164. function showValue() {
  165. suppliers_with_all_products = document.getElementById("suppliers_with_all_products");
  166. alert(suppliers_with_all_products.value);
  167. }
  168. function refreshProducts(element){
  169. var parent = element.parentNode; //right_col
  170. var supplier_id = element.id;
  171. var childs = parent.childNodes;
  172. var period_id = $('id');
  173. var params = new Array();
  174. if (parent.id == 'right_col') {
  175. for(var i = 0; i < childs.length; i++){
  176. if ('LI' == childs[i].nodeName) {
  177. var supplier_id = childs[i].id;
  178. supplier_id = supplier_id.substr(13, supplier_id.length - 13);
  179. params.push(supplier_id);
  180. }
  181. }
  182. var tidyParams = params.join(',');
  183. var url = '<?php echo url_for('kataoPeriod/refreshProducts') ?>';
  184. var myAjax = new Ajax.Request(
  185. url,
  186. {
  187. method: 'get',
  188. parameters: {
  189. suppliers_ids:tidyParams,
  190. id:period_id.value
  191. },
  192. onSuccess: manageResponse
  193. });
  194. }
  195. if (parent.id == 'middle_col' || parent.id == 'left_col') {
  196. var right_col = $('right_col');
  197. var childs_right_col = right_col.childNodes;
  198. for(var i = 0; i < childs_right_col.length; i++){
  199. if ('LI' == childs_right_col[i].nodeName) {
  200. var supplier_id = childs_right_col[i].id;
  201. supplier_id = supplier_id.substr(9, supplier_id.length - 9);
  202. params.push(supplier_id)
  203. }
  204. }
  205. var tidyParams = params.join(',');
  206. var url = '<?php echo url_for('kataoPeriod/refreshProducts') ?>';
  207. var myAjax = new Ajax.Request(
  208. url,
  209. {
  210. method: 'get',
  211. parameters: {
  212. suppliers_ids:tidyParams,
  213. id:period_id.value
  214. },
  215. onSuccess: manageResponse
  216. });
  217. }
  218. }
  219. function manageResponse(xhr){
  220. var products = xhr.responseText.evalJSON();
  221. var mySelect = '<select name="products[]" id="products" multiple="multiple" style="width:365px;">';
  222. var optSelect = new Array();
  223. products.selected.each(
  224. function (result)
  225. {
  226. optSelect = Object.values(result);
  227. });
  228. products.list.each(
  229. function (supplier)
  230. {
  231. //console.log(products.selected);
  232. for(var i = 0; i < all_supplier.length; i++){
  233. var product_list = eval('supplier["' + all_supplier[i] + '"]');
  234. if (product_list != undefined) {
  235. mySelect += '<optgroup label="'+all_supplier[i]+'">';
  236. product_list.each(
  237. function (opt_list)
  238. {
  239. var opt_names = Object.values(opt_list);
  240. var opt_ids = Object.keys(opt_list);
  241. for(var i = 0; i < opt_ids.length; i++){
  242. // mySelect += '<option value="'+opt_ids[i]+'">'+opt_names[i]+'</option>';
  243. if (in_array(opt_ids[i],optSelect)) {
  244. mySelect += '<option value="'+opt_ids[i]+'" selected="selected">'+opt_names[i]+'</option>';
  245. }else{
  246. mySelect += '<option value="'+opt_ids[i]+'">'+opt_names[i]+'</option>';
  247. }
  248. }
  249. });
  250. mySelect += '</optgroup>';
  251. }
  252. }
  253. });
  254. mySelect += '</select>';
  255. $('dynamic_product').update();
  256. $('dynamic_product').innerHTML
  257. $('dynamic_product').update(mySelect);
  258. $('dynamic_product').innerHTML
  259. }
  260. /* ]]> */
  261. </script>