Use Dynamic Checkbox
This commit is contained in:
		
							parent
							
								
									64624fa597
								
							
						
					
					
						commit
						01b5e9e868
					
				| 
						 | 
					@ -1056,11 +1056,32 @@ function sleep(milliseconds)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$(".custom").click(function() {
 | 
					$(".sccp-restore").click(function() {
 | 
				
			||||||
	$(this).parents(".element-container").removeClass("has-error");
 | 
					  //input is sent by data-for where for is an attribute
 | 
				
			||||||
	var id = $(this).data("for"), input = $("#" + id);
 | 
						var id = $(this).data("for"), input = $("#" + id);
 | 
				
			||||||
  var edit_style = document.getElementById("edit_" + id).style;
 | 
					  var edit_style = document.getElementById("edit_" + id).style;
 | 
				
			||||||
  console.log(id);
 | 
					
 | 
				
			||||||
 | 
					  console.log(input);
 | 
				
			||||||
 | 
						if (input.length === 0) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if ($(this).is(":checked")) {
 | 
				
			||||||
 | 
					    edit_style.display = 'block';
 | 
				
			||||||
 | 
							input.prop("readonly", true);
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
					    edit_style.display = 'none';
 | 
				
			||||||
 | 
							input.data("custom", input.val());
 | 
				
			||||||
 | 
							input.prop("readonly", true);
 | 
				
			||||||
 | 
							input.val(input.data("default"));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$(".sccp-edit").click(function() {
 | 
				
			||||||
 | 
					  //input is sent by data-for where for is an attribute
 | 
				
			||||||
 | 
						var id = $(this).data("for"), input = $("#" + id);
 | 
				
			||||||
 | 
					  var edit_style = document.getElementById("edit_" + id).style;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  console.log(input);
 | 
				
			||||||
	if (input.length === 0) {
 | 
						if (input.length === 0) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -88,11 +88,11 @@ foreach ($items as $child) {
 | 
				
			||||||
    if ($child['type'] == 'IE') {
 | 
					    if ($child['type'] == 'IE') {
 | 
				
			||||||
        $res_input = '';
 | 
					        $res_input = '';
 | 
				
			||||||
        $res_name = '';
 | 
					        $res_name = '';
 | 
				
			||||||
        $res_oid = (string)$child->input[0]->name;
 | 
					        $shortID = (string)$child->input[0]->name;
 | 
				
			||||||
        $res_id = $npref.$res_oid;
 | 
					        $res_id = $npref.$shortID;
 | 
				
			||||||
        if (!empty($metainfo[$res_oid])) {
 | 
					        if (!empty($metainfo[$shortID])) {
 | 
				
			||||||
            if ($child->meta_help == '1' || $child->help == 'Help!') {
 | 
					            if ($child->meta_help == '1' || $child->help == 'Help!') {
 | 
				
			||||||
                $child->help = $metainfo[$res_oid];
 | 
					                $child->help = $metainfo[$shortID];
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -172,7 +172,6 @@ foreach ($items as $child) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if ($child['type'] == 'IED') {
 | 
					    if ($child['type'] == 'IED') {
 | 
				
			||||||
        $res_input = '';
 | 
					        $res_input = '';
 | 
				
			||||||
        $res_name = '';
 | 
					 | 
				
			||||||
        $res_value = '';
 | 
					        $res_value = '';
 | 
				
			||||||
        $opt_at = array();
 | 
					        $opt_at = array();
 | 
				
			||||||
        $res_n =  (string)$child->name;
 | 
					        $res_n =  (string)$child->name;
 | 
				
			||||||
| 
						 | 
					@ -748,7 +747,6 @@ foreach ($items as $child) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if ($child['type'] == 'ITED') {
 | 
					    if ($child['type'] == 'ITED') {
 | 
				
			||||||
        $res_input = '';
 | 
					        $res_input = '';
 | 
				
			||||||
        $res_name = '';
 | 
					 | 
				
			||||||
        $res_na =  (string)$child->name;
 | 
					        $res_na =  (string)$child->name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//        $res_value
 | 
					//        $res_value
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -89,6 +89,7 @@ foreach ($items as $child) {
 | 
				
			||||||
        $res_input = '';
 | 
					        $res_input = '';
 | 
				
			||||||
        $res_name = '';
 | 
					        $res_name = '';
 | 
				
			||||||
        $usingSysDefaults = true;
 | 
					        $usingSysDefaults = true;
 | 
				
			||||||
 | 
					        // if there are multiple inputs, take the first for res_id and shortId
 | 
				
			||||||
        $shortId = (string)$child->input[0]->name;
 | 
					        $shortId = (string)$child->input[0]->name;
 | 
				
			||||||
        $res_id = $npref.$shortId;
 | 
					        $res_id = $npref.$shortId;
 | 
				
			||||||
        if (!empty($metainfo[$shortId])) {
 | 
					        if (!empty($metainfo[$shortId])) {
 | 
				
			||||||
| 
						 | 
					@ -121,31 +122,26 @@ foreach ($items as $child) {
 | 
				
			||||||
        <?php
 | 
					        <?php
 | 
				
			||||||
        // Can have multiple inputs for a field displayed with a separator
 | 
					        // Can have multiple inputs for a field displayed with a separator
 | 
				
			||||||
        foreach ($child->xpath('input') as $value) {
 | 
					        foreach ($child->xpath('input') as $value) {
 | 
				
			||||||
                $res_n =  (string)$value->name;
 | 
					            $res_n =  (string)$value->name;
 | 
				
			||||||
                $res_name = $npref . $res_n;
 | 
					            $res_name = $npref . $res_n;
 | 
				
			||||||
            if (empty($res_id)) {
 | 
					            //if (!empty($fvalues[$res_n])) {
 | 
				
			||||||
                $res_id = $res_name;
 | 
					                //if (!empty($fvalues[$res_n]['data'])) {
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (!empty($fvalues[$res_n])) {
 | 
					 | 
				
			||||||
                if (!empty($fvalues[$res_n]['data'])) {
 | 
					 | 
				
			||||||
                    if (!empty($sccp_defaults[$res_n]['systemdefault']) && ($sccp_defaults[$res_n]['systemdefault'] != $fvalues[$res_n]['data'])) {
 | 
					                    if (!empty($sccp_defaults[$res_n]['systemdefault']) && ($sccp_defaults[$res_n]['systemdefault'] != $fvalues[$res_n]['data'])) {
 | 
				
			||||||
                        $usingSysDefaults = false;
 | 
					                        $usingSysDefaults = false;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    $value->value = $fvalues[$res_n]['data'];
 | 
					                    $value->value = $fvalues[$res_n]['data'];
 | 
				
			||||||
                }
 | 
					                //}
 | 
				
			||||||
            }
 | 
					            //}
 | 
				
			||||||
            if (empty($value->value)) {
 | 
					            // Default to chan-sccp defaults, not xml defaults.
 | 
				
			||||||
                $value->value = $value->default;
 | 
					            //if (empty($value->value)) {
 | 
				
			||||||
            }
 | 
					                //$value->value = $sccp_defaults[$res_n]['systemdefault'];
 | 
				
			||||||
 | 
					            //}
 | 
				
			||||||
            if (empty($value->type)) {
 | 
					            if (empty($value->type)) {
 | 
				
			||||||
                $value->type = 'text';
 | 
					                $value->type = 'text';
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (empty($value->class)) {
 | 
					            if (empty($value->class)) {
 | 
				
			||||||
                $value->class = 'form-control';
 | 
					                $value->class = 'form-control';
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            // TODO: This is a temporary workaround and should be fixed
 | 
					 | 
				
			||||||
            $item = array('id' => $res_id, 'setting' => $child->label, 'feature' => $res_id, 'iscustom' => 'checked');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if ($i > 0) {
 | 
					            if ($i > 0) {
 | 
				
			||||||
                echo $child->nameseparator;
 | 
					                echo $child->nameseparator;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					@ -156,13 +152,36 @@ foreach ($items as $child) {
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
                    <div class="col-md-4">
 | 
					                    <div class="col-md-4">
 | 
				
			||||||
                      <span class="radioset">
 | 
					                      <span class="radioset">
 | 
				
			||||||
                        <input type="checkbox" data-for="<?php echo $item['id']?>" name="fc[<?php echo $item['setting']?>][<?php echo $item['feature']?>][customize]" class="custom" id="usedefault_<?php echo $item['id']?>" <?php echo ($usingSysDefaults) ? ':checked' : '';?>>
 | 
					                        <input type="checkbox"
 | 
				
			||||||
                        <label for="usedefault_<?php echo $item['id']?>"><?php echo ($usingSysDefaults) ? _("Customize") : _("Use chan-sccp defaults")?></label>
 | 
					                            <?php
 | 
				
			||||||
 | 
					                            if ($usingSysDefaults) {
 | 
				
			||||||
 | 
					                                // Setting a site specific value
 | 
				
			||||||
 | 
					                                echo " data-for={$res_id}";
 | 
				
			||||||
 | 
					                                echo " class=sccp-edit";
 | 
				
			||||||
 | 
					                                echo " id=usedefault_{$res_id}";
 | 
				
			||||||
 | 
					                                echo " :checked";
 | 
				
			||||||
 | 
					                            } else {
 | 
				
			||||||
 | 
					                                // reverting to chan-sccp default values
 | 
				
			||||||
 | 
					                                echo " data-for={$res_id}";
 | 
				
			||||||
 | 
					                                echo " class=sccp-restore";
 | 
				
			||||||
 | 
					                                echo " id=usedefault_{$res_id}";
 | 
				
			||||||
 | 
					                                echo " ";
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            ?>
 | 
				
			||||||
 | 
					                        >
 | 
				
			||||||
 | 
					                        <label
 | 
				
			||||||
 | 
					                            <?php
 | 
				
			||||||
 | 
					                            echo "for=usedefault_{$res_id} >";
 | 
				
			||||||
 | 
					                            echo ($usingSysDefaults) ? "Customise" : "Use chan-sccp defaults";
 | 
				
			||||||
 | 
					                            ?>
 | 
				
			||||||
 | 
					                        </label>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                      </span>
 | 
					                      </span>
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <div class="row" id="edit_<?php echo $res_id; ?>" style="display: none;">
 | 
					            <div class="row" id="edit_<?php echo $res_id; ?>" style="display: none">
 | 
				
			||||||
 | 
					    <!--        <div class="row" id="edit_<?php echo $res_id; ?>" style="display: none;"> -->
 | 
				
			||||||
                <div class="form-group <?php echo $res_sec_class; ?>">
 | 
					                <div class="form-group <?php echo $res_sec_class; ?>">
 | 
				
			||||||
                    <div class="col-md-3">
 | 
					                    <div class="col-md-3">
 | 
				
			||||||
                        <i><?php echo "Enter new site value for {$shortId}"; ?></i>
 | 
					                        <i><?php echo "Enter new site value for {$shortId}"; ?></i>
 | 
				
			||||||
| 
						 | 
					@ -182,8 +201,12 @@ foreach ($items as $child) {
 | 
				
			||||||
                                    $value->value = $fvalues[$res_n]['data'];
 | 
					                                    $value->value = $fvalues[$res_n]['data'];
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
 | 
					                            // Default to chan-sccp defaults, not xml defaults.
 | 
				
			||||||
                            if (empty($value->value)) {
 | 
					                            if (empty($value->value)) {
 | 
				
			||||||
                                $value->value = $value->default;
 | 
					                                $value->value = $sccp_defaults[$res_n]['systemdefault'];
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            if (!$usingSysDefaults) {
 | 
				
			||||||
 | 
					                                $value->value = $sccp_defaults[$res_n]['systemdefault'];
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                            if (empty($value->type)) {
 | 
					                            if (empty($value->type)) {
 | 
				
			||||||
                                $value->type = 'text';
 | 
					                                $value->type = 'text';
 | 
				
			||||||
| 
						 | 
					@ -194,7 +217,6 @@ foreach ($items as $child) {
 | 
				
			||||||
                            if ($i > 0) {
 | 
					                            if ($i > 0) {
 | 
				
			||||||
                                echo $child->nameseparator;
 | 
					                                echo $child->nameseparator;
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
//
 | 
					 | 
				
			||||||
                            echo '<input type="' . $value->type . '" class="' . $value->class . '" id="' . $res_id . '" name="' . $res_name . '" value="' . $value->value.'"';
 | 
					                            echo '<input type="' . $value->type . '" class="' . $value->class . '" id="' . $res_id . '" name="' . $res_name . '" value="' . $value->value.'"';
 | 
				
			||||||
                            if (isset($value->options)) {
 | 
					                            if (isset($value->options)) {
 | 
				
			||||||
                                foreach ($value->options ->attributes() as $optkey => $optval) {
 | 
					                                foreach ($value->options ->attributes() as $optkey => $optval) {
 | 
				
			||||||
| 
						 | 
					@ -226,7 +248,6 @@ foreach ($items as $child) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if ($child['type'] == 'IED') {
 | 
					    if ($child['type'] == 'IED') {
 | 
				
			||||||
        $res_input = '';
 | 
					        $res_input = '';
 | 
				
			||||||
        $res_name = '';
 | 
					 | 
				
			||||||
        $res_value = '';
 | 
					        $res_value = '';
 | 
				
			||||||
        $opt_at = array();
 | 
					        $opt_at = array();
 | 
				
			||||||
        $res_n =  (string)$child->name;
 | 
					        $res_n =  (string)$child->name;
 | 
				
			||||||
| 
						 | 
					@ -802,7 +823,6 @@ foreach ($items as $child) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if ($child['type'] == 'ITED') {
 | 
					    if ($child['type'] == 'ITED') {
 | 
				
			||||||
        $res_input = '';
 | 
					        $res_input = '';
 | 
				
			||||||
        $res_name = '';
 | 
					 | 
				
			||||||
        $res_na =  (string)$child->name;
 | 
					        $res_na =  (string)$child->name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//        $res_value
 | 
					//        $res_value
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue