⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Change Field Type After Render Or...?



mrtakdnz

mrtakdnz
  • profile picture
  • Member

Posted 01 April 2013 - 12:05 PM

I have a config table like:

CREATE TABLE `wfbp_config` (
	`id` INT(10) NOT NULL AUTO_INCREMENT,
	`type` VARCHAR(20) NOT NULL DEFAULT '0' COLLATE 'utf8_unicode_ci',
	`slug` VARCHAR(20) NOT NULL DEFAULT '0' COLLATE 'utf8_unicode_ci',
	`title` VARCHAR(50) NOT NULL DEFAULT '0' COLLATE 'utf8_unicode_ci',
	`description` VARCHAR(120) NOT NULL DEFAULT '0' COLLATE 'utf8_unicode_ci',
	`value` VARCHAR(120) NOT NULL DEFAULT '0' COLLATE 'utf8_unicode_ci',
        `values` VARCHAR(120) NOT NULL DEFAULT '0' COLLATE 'utf8_unicode_ci',
	PRIMARY KEY (`id`),
	UNIQUE INDEX `slug` (`slug`)
)
COLLATE='utf8_unicode_ci'
ENGINE=InnoDB;

 

I store config values at this table but...

 

I need to change value's field_type by type's column value, like:

 

if ($type=='image')
    $this->crud->set_field_upload('value', $this->config->item('upload_path'));
elseif ($type=='text')
    $this->crud->field_type('value','text');
elseif ($type=='date')
    $this->crud->field_type('value','date');
elseif ($type=='dropdown')
    $this->crud->field_type('value','date', explode(',', $values));

/* etc... */

 

But i have to change this after rendering the crud. And it's impossible (i guess). And i cannot achieve this with callbacks!

 

Is there any way to solve this with this table structure or is there any suggestion for a new table structure (but not all config values in one row).

 

For now i'm using multiple crud pages with unique config. like: sitename/panel/config-string/tr/system/ or sitename/panel/config-images/tr/system/ etc... i want to merge this values.

 

Thanks in advance.

 

P.S. I try to get config values like this:

 

Model:

    function get_config($config_slug) {
        
        $this->db->where('slug', $config_slug)
            ->where('lang', LANG_STR);
        $qr = $this->db->get('config');
        
        if ($qr->num_rows() == 1) {
            return $qr->row()->config_value;
        } else {
            return false;
        }
        
    }

 

Helper:

    function config($config_slug) {
        
        $wf=& get_instance();
        $wf->load->model('site_model');
        
        return $wf->site_model->get_config($config_slug);
        
    }

 

 

Thanks again...


Zalo

Zalo
  • profile picture
  • Member

Posted 03 April 2013 - 16:13 PM

Well... there is (as far as I know) no way to do this with the "standard" GC form BUT! you may be able to create "ghost" (that don't really exist on the database) hidden fields for each type, change which one to show with jQuery and set the right value with a callback_before_insert/update.

 

something like... 

 

On the controller:

$this->crud->set_field_upload('value', $this->config->item('upload_path'));
$this->crud->field_type('value_text','text');
$this->crud->field_type('value_date','date');
$this->crud->field_type('value_date2','date', explode(',', $values));

 

I have set the set_field_upload to the existing table field because I think that it doesn't work otherwise...

 

And on the callback you just have to see what type you have actually chosen and overwrite the $post['value'] value with the correct form value (for example, if you have set text... $post['value']=$post['value_text'])

 

About the edit:

If you assume that you can't change the 'type', a simple callback_edit_field would suffice (you get the $id of the row, so you can query for the type to set the field_type accordingly). Otherwise, just can use the same method I proposed to the add.

 

Hope it helped!

 

P.D.: One more idea: You can have many GCs to administer the same database, so you may be able to create one, generic, for listing with the add form disabled and then one for each type, with the type as a read only field with only the add form enable. Of course, you will have to create an add button for each type but it is easier than the first way... (also, not that preaty :p)


mrtakdnz

mrtakdnz
  • profile picture
  • Member

Posted 05 April 2013 - 12:09 PM

actually javascript solution is useful. But when i remove a field_box it, table stripes cannot re render and it appears like this: attachment

 

when i remove 2.nd (or whatever) box:

 

white
grey => remove this
white
gray

 

 

result:

 

 

white
white
gray

 


davidoster

davidoster
  • profile picture
  • Member

Posted 05 April 2013 - 17:17 PM

I suppose you need to run through, using js again to reimplement the background stripes.


Zalo

Zalo
  • profile picture
  • Member

Posted 05 April 2013 - 18:51 PM

The stripes are just a class, "odd" for white ones and "even" for gray ones. You should be able to reset them with a js just as david said.

Keep in mind that each field-box has it's own id so you may even set them manually for each one (even the ones that you hide).


mrtakdnz

mrtakdnz
  • profile picture
  • Member

Posted 05 April 2013 - 19:23 PM

oh yeah. My bad! sometimes i miss the point :) thanks for the help. so appreciated.