contents of "padlock_script.inc" to be added in the /wwwroot/js folder
<table id="controls_table" style="display:none;">
<Tr><Td style="text-align:center;">
<table class="atable" border="1" style="verticle-align:top;" id="addedControls" bgcolor="#F4F8E9">
<tbody>
<tr class="evenRow">
<th colspan="5">Selected Controlls</th>
</tr>
<tr id="emptyrow">
<td colspan="5" align="center">&nbsp;</td>
</tr>
</tbody>
</table>
</Td>
</Tr>
<tr>
<td><div id="padlock_buttons"></div></td>
</tr>
</Table>
<!-- </form> -->
<!-- </td></tr></table> -->
</div>
<style>
.atable {
border: 1px solid #AAAAAA;
border-collapse: collapse;
margin-left: -10px;
width: 100%;
}
.atable th {
background: none repeat scroll 0 0 #052D92;
border: 1px solid #AAAAFF;
font-weight: bold;
color:white;
}
.atable td {
border: 1px solid #FFFFFF;
padding: 4px;
}
.oddRow {
background: none repeat scroll 0 0 #FFFFFF;
}
.evenRow {
background: none repeat scroll 0 0 #DFDFFF;
}
.padlockBackground {
background: none repeat scroll 0 0 #DFDFFF;
}
.selectedControl{
border-color: red;
outline-color: red;
outline-style: solid;
outline-width: thin;
border:2px solid #CC0000;
}
</style>
<script>
jQuery.fn.exists = function(){return this.length>0;}
$(document).ready(function() {
//var role_id = '<?php echo $roleId;?>';
var role_id = 'Admin';
//user_id = 2;
if(role_id != 'Admin' ) {
var arr = '<?php echo Yii::app()->padLock->padLockContent; ?>';
if(arr!="") {
var padlockArray = new Array();
var object = jQuery.parseJSON(arr);
padlockArray['field'] = object.field;
padlockArray['visibility'] = object.visibility;
padlockArray['Enable'] = object.Enable;
var padlockFieldsArr = (padlockArray['field'].toString()).split(',');
var padlockvisibilityArr = (padlockArray['visibility'].toString()).split(',');
var padlockEnableArr = (padlockArray['Enable'].toString()).split(',');
var modelId = '<?php echo get_class($model);?>';
// Elements are not in form
$("form").find('input, textarea, select, li, ul, .padlock_control').each(function(){
var id = $(this).attr('id');
if(jQuery.inArray(id, padlockFieldsArr)>=0)
{
var array_Index = padlockFieldsArr.indexOf( id );
var visiblity = padlockvisibilityArr[array_Index];
var enable = padlockEnableArr[array_Index];
//alert("id="+id+", "+visiblity+", "+enable);
if(visiblity == "0") {
if ($("#lbl_"+id).exists()) {
$("#lbl_"+id).remove();
}
$("#"+id).remove();
}
if(enable == "0") {
$("#"+id).attr('disabled', true);
}
}
});
$("[id^='pdl_']").each( function() {
// alert($(this).attr('id'));
var id = $(this).attr('id');
if(jQuery.inArray(id, padlockFieldsArr)>=0)
{
var array_Index = padlockFieldsArr.indexOf( id );
var visiblity = padlockvisibilityArr[array_Index];
var enable = padlockEnableArr[array_Index];
//alert("id="+id+", "+visiblity+", "+enable);
$("#"+id).remove();
if ($("#"+id+"_data").exists()) { // table column removal
$("[id^="+id+"_data]").each(function() {
$(this).remove();
});
}
}
});
}
}
$('#padlock').click(function() {
$("select > option").remove();
$('select').append($('<option></option>').val('').html('----select----'));
$(".errorSummary").remove();
$(".errorMessage").remove();
$("a").each( function() {
$(this).attr('onclick','');
$(this).attr('href','#');
});
$("link[href='<?php echo Yii::app()->request->baseUrl; ?>/bootstrap/css/bootstrap.css']").remove();
addPadLockButtons();
var formId = $('#padlockForm').closest('form').attr('id');
var url = '<?php echo $this->createUrl('padLock/Insert');?>';
$("#"+formId).attr("action", url);
$("#"+formId).attr("name", "pdlForm");
$('#padlockForm').val("true");
$("#manage_button").html("<center><h3 style='color:#CC0000;'>WELCOME TO PADLOCK SCREEN</h3></center>");
$("#mainDiv_Padlock").addClass('padlockBackground');
$('#padlock').hide();
$('#controls_table').show("slow");
$('input, textarea, select, .padlock_control, [id^="pdl_"]').click(function()
{
var target_id = $(this).attr("id");
var hdnValue = $('#selectedFields').val();
if($(this).hasClass('selectedControl'))
{
$(this).removeClass('selectedControl');
$('#my_row_'+target_id).remove();
remove_id_from_hidden(target_id);
} else {
$(this).addClass('selectedControl');
/*********** checking wheather the control already added or not */
var n = hdnValue.search(new RegExp(target_id, "i"));
if(n == -1) {
$('#selectedFields').val(hdnValue +','+ target_id);
addTableRow('addedControls', target_id);
} else {
$('input:checkbox[value="' + target_id + '"]').attr('checked', true);
}
}
});
});
});
function remove_id_from_hidden(target_id) {
var hidden = $("#selectedFields");
var arr = hidden.val().split(","); // transforms the string into an array
arr.splice(arr.indexOf(target_id), 1); // removes the item from the array
hidden.val(arr.join(",")); // sets the value again
removeTableRow(target_id);
return;
}
function addTableRow(jQtable, target_id) {
default_chk_value = 'Checked';
var tds = '<tr id="my_row_'+target_id+'">';
tds += '<td><input type="checkbox" name="padlock_chk_fields[]" id="padlock_chk_fields" onclick="callme(this)" value="'+target_id+'" CHECKED=TRUE></td>';
tds += '<td>'+target_id+'</td>';
tds += '<td><input type="Radio" name="visibleProp_'+target_id+'" value="visible">Visible<br/><input type="Radio" name="visibleProp_'+target_id+'" value="invisible" checked>In-Visible<Br/></td>';
tds += '<td><input type="Radio" name="enableProp_'+target_id+'" value="enable">Enabled<br/><input type="Radio" name="enableProp_'+target_id+'" checked value="disable">Disabled<Br/></td>';
tds += '<td align="center"><img border="0" id="'+target_id+'" src="images/cross.gif" style="display: inline;" onClick=remove_id_from_hidden("'+target_id+'");></td>';
tds += '</tr>';
$('#'+jQtable).append(tds);
}
function removeTableRow(rowId) {
$('#my_row_'+rowId).remove();
$('#'+rowId).removeClass('selectedControl');
}
function addPadLockButtons() {
$.ajax({
type: "POST",
url: '<?php echo $this->createUrl('padLock/PadlockCommonFields');?>',
success: function(data){
$("#padlock_buttons").html(data);
}
});
}
function callme(chkfield){
if(chkfield.checked == false) {
$('#'+chkfield.value).removeClass('selectedControl');
//removeTableRow(chkfield.value);
} else {
$('#'+chkfield.value).addClass('selectedControl');
}
}
function getusersList() {
var selectedroles = '';
// getting checked checkbox values
$.each($("input[name='role[]']:checked"), function() {
selectedroles += (selectedroles?',':'') + "'"+$(this).attr('value')+"'";
});
$.ajax({
type: "POST",
url: '<?php echo $this->createUrl('padLock/ListUsers');?>',
data:'role='+selectedroles,
success: function(data){
$("#employeeData").html(data);
}
});
}
function submitPadlock() {
alert("xx");
$("form[name='pdlForm']").submit();
}
</script>