manageProductsByPeriodSuccess.php 7.5 KB

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