PageRenderTime 29ms CodeModel.GetById 12ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/magehelp/application/views/acl/resource_grid.php

https://bitbucket.org/jit_bec/shopifine
PHP | 337 lines | 291 code | 34 blank | 12 comment | 9 complexity | e13dbf1d6978e5bf09fc2c18053ee193 MD5 | raw file
  1<html>
  2    <head>
  3       <?php $this->load->view("common/header"); ?>
  4<!--        <script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>-->
  5        <link rel="stylesheet" rev="stylesheet" href="<?php echo base_url();?>css/shopifine.css" />
  6        <link rel="stylesheet" type="text/css" media="screen" href="<?php echo base_url(); ?>css/ui.jqgrid.css" />
  7        <script src="<?php echo base_url(); ?>js/i18n/grid.locale-en.js" type="text/javascript"></script>
  8        <script src="<?php echo base_url(); ?>js/jquery.jqGrid.min.js" type="text/javascript" language="javascript" charset="UTF-8"></script>
  9<!--        <script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/md5.js"></script>-->
 10         <script>
 11            $(document).ready(function(){
 12                
 13                
 14                //user grid
 15                $("#permissionForm").validate({
 16                    rules:{
 17                        relativeOrder:{
 18                            digits:true
 19                        }
 20                    }
 21                });
 22                $("#parent").combobox();
 23                var myGrid = $("#resources"),lastsel2;
 24                var editparameters = {
 25                    "keys" : true,
 26                    "oneditfunc" : null,
 27                    "successfunc" : function(){
 28                        var successStatus = "Resources successfully edited";
 29                        showSuccessMessage(successStatus);
 30                        lastsel2=undefined;
 31                        myGrid.trigger("reloadGrid");
 32                        return true;
 33                    },
 34                    "aftersavefunc" : null,
 35                    "errorfunc": function(response)
 36                        {
 37                            var errorStatus = " Resources could not be updated due to internal error";
 38                            showErrorMessage(errorStatus);
 39                            lastsel2=undefined;
 40                        },
 41                    "afterrestorefunc" : null,
 42                    "restoreAfterError" : true,
 43                    "mtype" : "POST"
 44                };
 45                myGrid.jqGrid({
 46                    url:'index.php/acls/populateResources',
 47                    datatype: 'json',
 48                    mtype: 'GET',
 49                    colNames:['Resource','Resource Type Id','Parent Resource Id','Resource Type','Parent Resource','Description','UI Display Name','Relative Path','Relative Order'],
 50                    colModel :[ 
 51                        {name:'resource', index:'resource', width:100, align:'right',editable:false,editrules:{required:true},editoptions:{size:"20",maxlength:"30"}},
 52                        {name:'resource_type_id', index:'resource_type_id', hidden:true},
 53                        {name:'parent_id', index:'parent_id', hidden:true},
 54                        {name:'resource_type', index:'resource_type', width:80, align:'right',editable:false,editrules:{required:true},edittype:"select",editoptions:{dataUrl:"index.php/acls/populateResourceTypesEdit",buildSelect:function(response)
 55                        {
 56                            var select = "<select name=" + "resOpEdit" + "id =" +"resOpEdit" +">" +
 57                                        "<option value=" + ">Select one..." + response + "</select>";
 58                                    
 59                            return select;
 60                        }}},
 61                        {name:'parent', index:'parent', width:100, align:'right',editable:false,edittype:"select",editoptions:{dataUrl:"index.php/acls/populateParentResourcesEdit",buildSelect:function(response)
 62                        {
 63                            var select = "<select name=" + "parentOpEdit" + "id =" +"parentOpEdit" +">" +
 64                                        "<option value=" + ">Select one..." + response + "</select>";
 65                                    
 66                            return select;
 67                        }}},
 68                        {name:'description',index:'description', width:120, align:'right',editable:true,editoptions:{size:"20",maxlength:"30"}},
 69                        {name:'ui_display_name', index:'ui_display_name', width:100, align:'right',editable:true,editrules:{},editoptions:{size:"20",maxlength:"30"}},
 70                        {name:'relative_path_link', index:'relative_path_link', width:140, align:'right',editable:true,editoptions:{size:"30",maxlength:"80"}},
 71                        {name:'relative_order_in_category', index:'relative_order_in_category', width:80, align:'right',editable:true,editoptions:{size:"20",maxlength:"30"}}
 72                    ],
 73                    pager: '#pager',
 74                    rowNum:10,
 75                    rowList:[5,10,20],
 76                    sortname: 'id',
 77                    sortorder: 'desc',
 78                    viewrecords: true,
 79                    gridview: true,
 80                    ignoreCase:true,
 81                    rownumbers:true,
 82                    height:'auto',
 83                    width:'auto',
 84                    caption: 'Resources',
 85            
 86                    jsonReader : {
 87                        root:"resourcedata",
 88                        page: "page",
 89                        total: "total",
 90                        records: "records",
 91                        cell: "dprow",
 92                        id: "id"
 93                    },
 94//                    onSelectRow: function(id){if(id && id!==lastsel2){
 95//                            myGrid.restoreRow(lastsel2);
 96//                            myGrid.editRow(id,editparameters);
 97//                            lastsel2=id;
 98//                        }
 99//                    },
100                    editurl:'index.php/acls/editResource'
101                    
102                }).navGrid("#pager",{edit:false,add:false,del:false,search:false},
103               /* edit Option*/ {height:280,reloadAfterSubmit:false,closeAfterEdit:true,recreateForm:true,checkOnSubmit:true},
104            /* Add Option*/     {                  
105                },{},{},{});
106        myGrid.jqGrid('navButtonAdd','pager',{
107            caption:"", 
108            title:"Add Resource",
109            buttonicon:"ui-icon-plus",
110            id:"add_resources",
111            onClickButton : function () { 
112                //need to pass grid id for dynamic reload;
113                
114                var gridData ={'oper':'add'}
115                 $( "#permission-form-dialog" ).data('grid_data',gridData).dialog( "open" );
116             } 
117         });
118          myGrid.jqGrid('navButtonAdd','pager',{
119            caption:"", 
120            title:"Edit Resource",
121            buttonicon:"ui-icon-pencil",
122            id:"edit_resources",
123            onClickButton : function () { 
124                //need to pass grid id for dynamic reload;
125                var rowid = myGrid.getGridParam('selrow');
126                if (rowid !=null && rowid!=undefined){
127                    var gridData ={'oper':'edit','resource_id':rowid};
128                     $( "#permission-form-dialog" ).data('grid_data',gridData).dialog( "open" );
129                }
130                else{
131                    $( "#modal-warning-one" ).dialog('open');
132                }
133
134             } 
135         });
136        myGrid.jqGrid('filterToolbar', {stringResult: true, searchOnEnter: true, defaultSearch : "cn"});
137                
138        $( "#permission-form-dialog" ).dialog({
139            autoOpen: false,
140            height: 'auto',
141            width: '35%',
142            position:[450,25],
143            modal: true,
144            buttons: {
145                "Add Resource": function() {
146                    //default form name
147                  
148                   var isvalid = $("#permissionForm").valid();
149                   
150                   if (isvalid){
151                       $.ajax({
152                           url:"index.php/acls/editResource",
153                           type:"POST",
154                           data:{
155                              
156                               form_data:$("#permissionForm").toObject()
157                               
158                           },
159                               
160                           success:function (response){
161                               console.log("success" + response)
162                           },
163                           error :function (response){
164                                                            
165                           }
166                           
167                       })
168                       $( this ).dialog( "close" );
169                   }
170
171                },
172                Cancel: function() {
173
174                    $( this ).dialog( "close" );
175                }
176            },
177            open: function(event,ui){
178                var oper = $(this).data("grid_data").oper;
179                var resource_id = $(this).data("grid_data").resource_id;
180                
181                if (oper=='add'){
182                    $("#permTypeCntnr").show();
183                    $("#oper_hidden").val(oper);
184                }
185                else if (oper=='edit'){
186                    //no change of default during edit.
187                    $("#permTypeCntnr").hide();
188                    var parent_id = $("#resources").getCell(resource_id,'parent_id');
189                    if (!isEmpty(parent_id)){
190                        $("#parent").combobox("setselected",parent_id);
191                    }
192                    
193                    $("#oper_hidden").val(oper);
194                    $("#resource_id_hidden").val(resource_id);
195                    $("#resource").val($("#resources").getCell(resource_id,'resource'));
196                    $("#resourceType").val($("#resources").getCell(resource_id,'resource_type_id'));
197                    
198                    $("#description").val($("#resources").getCell(resource_id,'description'));
199                    $("#uiDisplayName").val($("#resources").getCell(resource_id,'ui_display_name'));
200                    $("#relativePath").val($("#resources").getCell(resource_id,'relative_path_link'));
201                    $("#relativeOrder").val($("#resources").getCell(resource_id,'relative_order_in_category'));
202                  
203                }
204
205            },
206            close: function(event,ui) {
207                $("#permissionForm").data('validator').resetForm();
208                $('#permissionForm')[0].reset();
209                $("#resources").trigger('reloadGrid');
210            }
211        });
212        //for submenu parent is required
213        $("#resourceType").change(function(){
214            if ($(this).val()=="3"){
215                $("#parent-input").addClass("required");
216            }
217            else {
218                $("#parent-input").removeClass("required");
219            }
220        });
221
222    });
223     $(window).load(function(){
224       
225        var warningDialogs={one:true,none:true};
226        initDialogs(warningDialogs);
227        
228    });
229        </script>
230    </head>
231     
232    <body>
233         <?php $this->load->view("common/menubar"); ?>
234        <?php $this->load->view("common/dialogs"); ?>
235        
236        <div style="display: block;height: 100%;width:90%;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">
237            <?php //$this->load->view("common/message"); ?>
238            <div class="table-grid">
239                <h1 id="table header">Resources</h1>
240                <table id="resources"><tr><td/></tr></table> 
241                <div id="pager"></div>
242            </div>
243        </div>
244        <div id ="permission-form-dialog">
245            <h1 id="formHeader">Add New Resource</h1>   
246            <form id="permissionForm">
247                <fieldset>
248                    
249                    <div class="row single-column-row">
250                        <div class="column quote-column single-column">
251                           <div class="field">
252                                <label for="resource" class="labeldiv-edit">Resource:</label>  
253                                <input id="resource" name ="resource" type="text" class="required"/>
254                            </div>
255                        </div>
256                    </div>
257                    <div class="row single-column-row">
258                        <div class="column quote-column single-column">
259                            <div class="field">
260                                <label for="resourceType" class="labeldiv-edit">Resource Type:</label>  
261                                <select name="resourceType" id ="resourceType" class="required"> 
262                                    <option value="">Choose 
263                                        <?= $resourceTypeOptions ?> 
264                                </select>
265                            </div>
266                        </div>
267                    </div>
268                    <div class="row single-column-row" id="permTypeCntnr">
269                        <div class="column quote-column single-column">
270                            <div class="field">
271                                <label for="permissionType" class="labeldiv-edit">Default Permission Type:</label>  
272                                <select name="permissionType" id ="permissionType" class="required"> 
273                                    <option value="">Choose 
274                                        <?= $permissionTypeOptions ?> 
275                                </select>
276                                <div id ="permission-help" class="ui-corner-all help-message-left">
277                                    (For Administrator Role)
278                                </div>
279                            </div>
280                        </div>
281                    </div>
282                    <div class="row single-column-row">
283                        <div class="column quote-column single-column">
284                            <div class="field">
285                                <label for="parent" class="labeldiv-edit">Parent Resource:</label>  
286                                <select name="parent" id ="parent"> 
287                                    <option value="">Choose 
288                                        <?= $parentOptions ?> 
289                                </select>
290                            </div>
291                        </div>
292                    </div>
293                    <div class="row single-column-row">
294                        <div class="column quote-column single-column">
295                            <div class="field">
296                                <label for="description" class="labeldiv-edit">Description:</label>  
297                                <input id="description" name="description"/>
298                            </div>
299                        </div>                        
300                    </div>
301                    <div class="row single-column-row">
302                        <div class="column quote-column single-column">
303                            <div class="field">
304                                <label for="uiDisplayName" class="labeldiv-edit">UI Display Name:</label>  
305                                <input id="uiDisplayName" name="uiDisplayName"/>
306                                
307                            </div>
308                           
309                        </div>                        
310                    </div>
311                    <div class="row single-column-row">
312                        <div class="column quote-column single-column">
313                            <div class="field">
314                                <label for="relativePath" class="labeldiv-edit">Relative Path:</label>  
315                                <input id="relativePath" name="relativePath" size="30" maxlength="100"/>
316                                
317                            </div>
318                        </div>                        
319                    </div>
320                    <div class="row single-column-row">
321                        <div class="column quote-column single-column">
322                            <div class="field">
323                                <label for="relativeOrder" class="labeldiv-edit">Relative Order:</label>  
324                                <input id="relativeOrder" name="relativeOrder"/>
325                            </div>
326                        </div>
327                        
328                    </div>
329                    
330                </fieldset>
331                <input id="resource_id_hidden" name="resource_id_hidden" type="hidden"/>
332                <input id="oper_hidden" name="oper_hidden" type="hidden"/>
333            </form>
334        </div>
335        <?php $this->load->view("partial/footer"); ?>
336    </body>
337</html>