PageRenderTime 49ms CodeModel.GetById 36ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/magehelp/application/views/products/product_category_grid.php

https://bitbucket.org/jit_bec/shopifine
PHP | 240 lines | 199 code | 36 blank | 5 comment | 7 complexity | 7e437068e925bc518584e922566eefab MD5 | raw file
  1<html>
  2    <head>
  3       <?php $this->load->view("common/header"); ?>
  4         <script src="<?php echo base_url();?>js/jquery.jstree.js" type="text/javascript" language="javascript" charset="UTF-8"></script>
  5        <style>
  6            .ui-combobox > input{
  7                width:20em;
  8            }
  9            
 10            .ui-combobox > a{
 11                left:170px;
 12            }
 13            .column {width:400px;}
 14            .field {width:45em;}
 15        </style>
 16         <script>
 17            $(document).ready(function(){
 18                
 19                
 20                 $.validator.addMethod('treerequired', function(value, element) {
 21                    var selArray = $('#treeViewDiv').jstree('get_selected');
 22                    console.log(selArray.length);
 23                    alert (selArray.length);
 24                    if (selArray.length == 0){
 25                       
 26                            return false;
 27                       
 28                    }
 29                    return true;
 30                }, 'Please select a category');
 31
 32                $( "#productForm" ).validate({
 33                    errorPlacement: function(error, element) {
 34                        error.appendTo( element.parent());
 35                    }//,
 36                    //            rules: {
 37                    //                        mfrOp: {
 38                    //                            comboBoxrequired: true
 39                    //                        }
 40                    //                    }
 41            
 42                }
 43            );   
 44                
 45                
 46                 $( "#dialog:ui-dialog" ).dialog( "destroy" );
 47                 
 48                  $("#productOp").combobox();  
 49                  
 50                  
 51                 
 52                $( "#dialog-form" ).dialog({
 53                    autoOpen: false,
 54                    height: 'auto',
 55                    width: '40%',
 56                    position:[350,25],
 57                    modal: true,
 58                    buttons: {
 59                        "Add Category To Products": function() {
 60                           var bValid =  $("#productForm").valid();
 61                    
 62                            if (bValid ){
 63                                var selectedIds = [];
 64                                $('#treeViewDiv').jstree('get_selected').each(function(){
 65                                    selectedIds.push($(this).attr('id'));
 66                                });
 67                        
 68                                $.ajax({
 69                                    url:"index.php/products/addcategoryToProduct",
 70                                    data: {
 71                                            
 72                                            productOp : $("#productOp").val(),
 73                                            productIp: $("#productOp-input").val(),
 74                                            category:JSON.stringify(selectedIds)
 75                                            },
 76                                
 77                                    type:"POST",
 78                                    success:function(serverresponse)
 79                                    {
 80                                        showSuccessMessage("Product Suceessfully Added To category");
 81                                        $("#resources").trigger("reloadGrid");
 82                                    }
 83                                });
 84                        
 85                                $( this ).dialog( "close" );
 86                            }
 87                    
 88                        },
 89                        Cancel: function() {
 90                            $( this ).dialog( "close" );
 91                        }
 92                    },
 93                    close: function() {
 94                        $("#productForm").data('validator').resetForm();
 95                        $('#productForm')[0].reset();
 96                    }
 97                });
 98                
 99
100                var myGrid = $("#resources");
101               
102                myGrid.jqGrid({
103                    url:'index.php/products/populateProductCategoryMapping',
104                    datatype: 'json',
105                    mtype: 'GET',
106                    colNames:['Product','Barcode','Product ID','Category ID','Category'],
107                    colModel :[ 
108                        {name:'product_name', index:'product_name', width:140, align:'right',editable:false,search:false},
109                        {name:'barcode', index:'barcode', width:140, align:'right',editable:false},
110                        {name:'product_id', index:'product_id', width:100, align:'right',hidden:true},
111                        {name:'category_id', index:'category_id', width:100, align:'right',hidden:true},
112                        {name:'category_name', index:'category_name', width:140, align:'right',editable:false},
113                        
114                    ],
115                    pager: '#pager',
116                    rowNum:10,
117                    rowList:[5,10,20],
118                    sortname: 'id',
119                    sortorder: 'desc',
120                    viewrecords: true,
121                    gridview: true,
122                    ignoreCase:true,
123                    rownumbers:true,
124                    height:'auto',
125                    width:'auto',
126                    multiselect:true,
127                    caption: 'Product Category Mapping',
128            
129                    jsonReader : {
130                        root:"productcategorydata",
131                        page: "page",
132                        total: "total",
133                        records: "records",
134                        cell: "dprow",
135                        id: "id"
136                    }
137                   
138                    
139                }).navGrid("#pager",{edit:false,add:false,del:false,search:false},
140               /* edit Option*/ {},
141            /* Add Option*/     {reloadAfterSubmit:true,recreateForm:true},
142                                                 {},{},{});
143               
144                myGrid.jqGrid('filterToolbar', {stringResult: true, searchOnEnter: true, defaultSearch : "cn"});
145                var settingsObj ={grid_id:'resources',pager:'pager'};
146                var buttons = {add_cat:true,del_cat:true};
147                addCustomButtonsInProductsGrid(settingsObj, buttons);
148                $("#add_resources").insertBefore("#del_resources")
149                 
150                  $("#treeViewDiv")
151                        .jstree({
152               "plugins" : ["themes", "json_data", "ui"],
153               "json_data" : {
154                   "ajax" : {
155                       "type": 'GET',
156                       "url": function (node) {
157                           var nodeId = "";
158                           var url = ""
159                           if (node == -1)
160                           {
161                               url = "index.php/utilities/renderParents";
162                           }
163                           else
164                           {
165                               nodeId = node.attr('id');
166                               url = "index.php/utilities/renderChildren";
167                           }
168
169                           return url;
170                       },
171                       data : function(node) {
172                           if (node != -1){
173                               return {
174
175                                 "nodeid":$.trim(node.attr('id'))
176                               }
177                           }
178                   },
179                       "success": function (new_data) {
180                           return new_data;
181                       }
182                   }
183               }});  
184            });
185            $(window).load(function(){
186       
187                var warningDialogs={one:true,none:true,status:true,exactlyone:true,morethanone:true};
188                initDialogs(warningDialogs);
189                initDeleteDialog();
190                
191            });
192        </script>
193    </head>
194     
195    <body>
196         <?php $this->load->view("common/menubar"); ?>
197        <?php  $this->load->view("common/dialogs"); ?>
198        <div id ="dialog-form">
199            <h1 id="formHeader">Add Category</h1>   
200            <form id="productForm">
201                <fieldset>
202                    
203                    <div class="row">
204                        <div class="column">
205                            <div class="field">
206                                <label for="productOp">Products:</label>  
207                                <select name="productOp" id ="productOp" class="required"> 
208                                    <option value="">Choose 
209                                        <?= $productOptions ?> 
210                                </select>
211                                <!--<button id="test"> test</button>-->
212                            </div>
213                        </div>
214                    </div>
215                    
216                    <div class="row">
217                        <div class="column">
218                            <div class="field">
219                                <label for="categoryOp">Category:</label>  
220                                <div id="treeViewDiv" style="display:inline-block">
221                                </div>
222                                <input id="treeViewHidden" name ="treeViewHidden" style="display:inline-block" class="treerequired" type="hidden"/>
223                            </div>
224                        </div>
225                    </div>
226                </fieldset>
227            </form>
228        </div>
229        
230        <div style="display: block;height: 100%;left:0em;" class="shopifine-ui-dialog  ui-widget ui-widget-content ui-corner-all" tabindex="-1" role="dialog" aria-labelledby="ui-dialog-title-dialog-form">
231            <?php $this->load->view("common/message"); ?>
232            <div class="table-grid">
233                <h1 id="table header">Products And Categories</h1>
234                <table id="resources"><tr><td/></tr></table> 
235                <div id="pager"></div>
236            </div>
237        </div>
238        <?php $this->load->view("partial/footer"); ?>
239    </body>
240</html>