Jump to content


ezgoen

Member Since 21 Mar 2013
Offline Last Active May 20 2013 08:17 AM
-----

Posts I've Made

In Topic: to set_relation_n_n or not?

20 May 2013 - 02:23 AM

I wont say I solved my problem - but I did hack around it.

 

If anyone has any suggestions for a cleaner way to do this - I'm open to suggestions.

 

I created a custom_gc_model with the following code:

function get_relation_n_n_already_used_array($field_info)
    {
    	$select = "";    	
    	$related_field_title = $field_info->title_field_selection_table;
    	$use_template = strpos($related_field_title,'{') !== false;;
    	$field_name_hash = $this->_unique_field_name($related_field_title);
    	if($use_template)
    	{
    		$related_field_title = str_replace(" ", " ", $related_field_title);
    		$select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash";
    	}
    	else
    	{
    		$select .= "$related_field_title as $field_name_hash";
    	}
    	$this->db->select('*, '.$select,false);
    	
    	$selection_primary_key = $this->get_primary_key($field_info->selection_table);
    	 
    	if(empty($field_info->priority_field_relation_table))
    	{
    		if(!$use_template){
    			$this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}");
    		}
    	}
    	else
    	{
    		$this->db->order_by("{$field_info->relation_table}.{$field_info->priority_field_relation_table}");
    	}
    	$this->db->join(
    			$field_info->selection_table,
    			"{$field_info->relation_table}.{$field_info->primary_key_alias_to_selection_table} = {$field_info->selection_table}.{$selection_primary_key}"
    		);
    	$results = $this->db->get($field_info->relation_table)->result();
    	
    	$results_array = array();
    	foreach($results as $row)
    	{
    		$results_array[$row->{$field_info->primary_key_alias_to_selection_table}] = $row->{$field_name_hash};
    	}
    			 
    	return $results_array;
    }
	
	
	
	function get_relation_n_n_unselected_array($field_info, $selected_values)
    {
	
		$already_used=$this->get_relation_n_n_already_used_array($field_info);
	
    	$use_where_clause = !empty($field_info->where_clause);
    	
    	$select = "";
    	$related_field_title = $field_info->title_field_selection_table;
    	$use_template = strpos($related_field_title,'{') !== false;
    	$field_name_hash = $this->_unique_field_name($related_field_title);
    	
    	if($use_template)
    	{
    		$related_field_title = str_replace(" ", " ", $related_field_title);
    		$select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash";
    	}
    	else
    	{
    		$select .= "$related_field_title as $field_name_hash";
    	}
    	$this->db->select('*, '.$select,false);
    	
    	if($use_where_clause){
    		$this->db->where($field_info->where_clause);	
    	}
    	
    	$selection_primary_key = $this->get_primary_key($field_info->selection_table);
        if(!$use_template)
        	$this->db->order_by("{$field_info->selection_table}.{$field_info->title_field_selection_table}");
        $results = $this->db->get($field_info->selection_table)->result();
	    $results_array = array();
        foreach($results as $row)
        {
            if(!isset($already_used[$row->$selection_primary_key]))
                $results_array[$row->$selection_primary_key] = $row->{$field_name_hash};
        }
        
        return $results_array;       
    }

Your thoughts ??

 

 

Cheers

 

Ez


In Topic: Active / Inactive bit field on add

05 May 2013 - 11:49 PM

I have posted this in github now - and since 

have discovered that defaults are not set for successive adds for any fields.

Perhaps this is why the default value feature is only partially implemented??

 

I must admit I didnt check the multi add functionality either when I built my own default value feature.

 

I think the way to go is to pass a javascript array of default values and have the fields set to these on add.

The problem here is it could get nasty, how far is it worth going for default values?

One might want to have the default value increment - would need to tell js thats what we want.

OR we might want next index id from the database - we would have to return that inside the ajax/json 

form post. But there's no reliable way to get next insert id - should be ok because we should be using auto increment feature of the database and therefor NOT need a default value.

 

Still bears some thinking as to the best way forward

 

 

Cheers

 

 

Ez


In Topic: Active / Inactive bit field on add

24 April 2013 - 01:48 AM

Ok

 

I hacked around the problem - its a bit brittle, perhaps someone can offer a more elegant approach.

 

You probably know I use a subclass of grocery_crud - so I can make my own changes on the fly

without touching the underlying code.

 

so I duplicated and modified get_true_false_input like so .

protected function get_true_false_input($field_info,$value)
	{
		$this->set_css($this->default_css_path.'/jquery_plugins/uniform/uniform.default.css');
		$this->set_js($this->default_javascript_path.'/jquery_plugins/jquery.uniform.min.js');
		$this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.uniform.config.js');
		
		$value_is_null = empty($value) && $value !== '0' && $value !== 0 ? true : false;
		
		$input = "<div class='pretty-radio-buttons'>";
		
		$checked = $value === '1' || ($value_is_null && $field_info->default === '1') ? "checked = 'checked'" : "";
		//set up a class name to add to the input field that tells us if its supposed to default to checked - 
		//we use this in flexigrid add
		$initial_checked = $value === '1' || ($value_is_null && $field_info->default === '1') ? " radio-default" : "";
		$input .= "<label><input id='field-{$field_info->name}-true' class='radio-uniform{$initial_checked}'  type='radio' name='{$field_info->name}' value='1' $checked /> ".$this->default_true_false_text[1]."</label> ";
		
		$checked = $value === '0' || ($value_is_null && $field_info->default === '0') ? "checked = 'checked'" : ""; 
		//set up a class name to add to the input field that tells us if its supposed to default to checked - 
		//we use this in flexigrid add$initial_checked = $value === '0' || ($value_is_null && $field_info->default === '0') ? " radio-default" : "";
		$input .= "<label><input id='field-{$field_info->name}-false' class='radio-uniform{$initial_checked}' type='radio' name='{$field_info->name}' value='0' $checked /> ".$this->default_true_false_text[0]."</label>";
		
		$input .= "</div>";
		
		return $input;
	}	
	

 

 

 

then I patched flexigrid-add.js like so:

 

	function clearForm()
	{
		$('#crudForm').find(':input').each(function() {
	        switch(this.type) {
	            case 'password':
	            case 'select-multiple':
	            case 'select-one':
	            case 'text':
	            case 'textarea':
	                $(this).val('');
	                break;
	            case 'checkbox': 
					this.checked = false;
					break;
	            case 'radio':
					/*use classnames to determine if this is default or not */
					if ($(this).hasClass('radio-default')){
						this.checked = true;
						/*little hack for the uniform plugin */
						if (!$(this).parent().hasClass('checked')){
							$(this).parent().addClass('checked');
						};
					
					} else {
						this.checked = false;
						if ($(this).parent().hasClass('checked')){
							$(this).parent().removeClass('checked');
						}; 
					}
			}
	    });

 

 

Presto, problem fixed - for now.

 

The check boxes probably need a similar treatment - but I'm not currently using them.

 

Should this logged somewhere as a bug???

 

 

Cheers

 

 

Ez


In Topic: Active / Inactive bit field on add

24 April 2013 - 12:45 AM

I found the culprit 

 

its in flexigrid-add.js

function clearForm()
	{
		$('#crudForm').find(':input').each(function() {
	        switch(this.type) {
	            case 'password':
	            case 'select-multiple':
	            case 'select-one':
	            case 'text':
	            case 'textarea':
	                $(this).val('');
	                break;
/* This sets the checked value to false - when it probably shouldn't 
   what if (like in my case) there is a default value 
   and should a group of radio buttons representing true or false 
   ever really have no checked items??
*/
	            case 'checkbox':
	            case 'radio':
	                this.checked = false;
	        }
	    });

		/* Clear upload inputs  */
		$('.open-file,.gc-file-upload,.hidden-upload-input').each(function(){
			$(this).val('');
		});
		
		$('.upload-success-url').hide();
		$('.fileinput-button').fadeIn("normal");
		/* -------------------- */		
		
		$('.remove-all').each(function(){
			$(this).trigger('click');
		});
		
		$('.chosen-multiple-select, .chosen-select, .ajax-chosen-select').each(function(){
			$(this).trigger("liszt:updated");
		});
	}

 

When the form fist loads it exhibits the correct behavior

after "save" the field becomes unchecked and no longer set to its default.

 

How should I approach this - embed some js variables that this function checks for default values or ???

 

 

Cheers

 

 

Ez


In Topic: Superfish Menu CI plugin

20 April 2013 - 01:28 PM

is it worth it?