⚠ In case you've missed it we are migrating 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 forum is read-only and soon will be archived. ⚠


KaBaDaBrA

Member Since 28 Feb 2012
Offline Last Active Nov 20 2012 07:47 AM
*****

#1684 multiple delete selection

Posted KaBaDaBrA on 09 May 2012 - 07:52 PM

For your number 2 I tested something quickly and works quite well, however it is static - not sure how to find the dynamically parsed values in the list like the table name being used, nor the field for the primary id. If I could find them it's really easy to change over to be dynamic. Maybe Johnny could give a hand here ;)

Anyway here we go:

example.PNG

Above is an example, added the check links to the side and a delete all selected button to the bottom right. Here is the "list.php" file, download it and copy to your flexigrid theme (backup your current one) path: assets\grocery_crud\themes\flexigrid\views.

Attached File  list.php   4.02K   2808 downloads

You will need to edit the javascript part around line 25 and replace your own URL in here.

Here's an example function for the controller:

function delete_selection()
{
   $id_array = array();
   $selection = $this->input->post("selection", TRUE);
   $id_array = explode("|", $selection);

   foreach($id_array as $item):
	  if($item != ''):
	  //DELETE ROW
	  $this->db->where('customerNumber', $item);
	  $this->db->delete('customers');
	  endif;
   endforeach;
}



#1460 [ANSWERED] How to add fancybox in Grocery Crud

Posted KaBaDaBrA on 25 April 2012 - 06:22 PM

Hahaha thanks John... I need to sit sometime and make a few good tutorials, been so hectic with work lately... But mostly respect goes to you man! Grocery CRUD amazing piece of work!!!! :P


#1458 [ANSWERED] set_relation and "Add New" button to quick insert.

Posted KaBaDaBrA on 25 April 2012 - 06:08 PM

Aloha!! :D

K well I think I know what you might want - so might have a solution for you. I quickly helped some other guys with a fancybox question, here's how you can do something similar:

1. Download Fancybox: http://fancyapps.com/fancybox/

2. Add this code to the view file (You'll have to change a few of the paths and names etc)


<link rel="stylesheet" href="<?=base_url()?>assets/plugins/fancybox/jquery.fancybox.css?v=2.0.6" type="text/css" media="screen" />
<script type="text/javascript" src="<?=base_url()?>assets/plugins/fancybox/jquery.fancybox.pack.js?v=2.0.6"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".various").fancybox();

//ADD IN A BUTTON TO ADD TO DROPDOWN
$('#countryID_input_box').append('<a href="<?=site_url()?>/examples/quick_add/" class="various fancybox.ajax">Add</a>');
});
</script>

3. Add this code to you controller (Again you will have to make modifications to work with your own code)


function quick_add()
{
  //EDIT BELOW TO ADD YOU SELECT NAME VALUE
  $args = array(
'category_name' => 'select[name="countryID"]'
  );

  $javascript = '
  <script>
  function do_quick_add()
  {
var category_text = $(\'#category_item\').val();
var category_id = $(\''.$args['category_name'].'\').val();

$.post(\''.site_url().'/examples/quick_add_save/\', { categoryID: category_id, category_item: category_text }, function(data) {
//PREPEND DATA TO SELECT BOX
$(\''.$args['category_name'].'\').prepend(\'<option value="\'+data+\'">\'+category_text+\'</option>\');
//REBUILD SELECT BOX
$(\''.$args['category_name'].'\').trigger("liszt:updated");
//DISPLAY SUCCESS MESSAGE
$(\'#category_message\').html(\'Successfully inserted a new category\');
});
  }
  </script>
  ';

  $html = '
  <div style="width: 400px; height: 250px;">
  <div style="padding: 5px;">New Category Name:</div>
  <div style="padding: 5px;"><input type="text" name="category_item" id="category_item"></div>
  <div style="padding: 5px;"><input type="button" value="Add &raquo;" onclick="do_quick_add();"> <span id="category_message"></span></div>
  </div>
  ';

  echo $javascript.$html;
  exit;
}

function quick_add_save()
{
//POST ITEMS
$categoryID = $this->input->post('categoryID', true); //only needed if adding a sub category, can get parent ID
$category_text = $this->input->post('category_item', true);

//SAVE TO DATABASE
$data = array(
'country_title' => $category_text
);
$this->db->insert('country', $data);

return $this->db->insert_id();
}

VOILA!!!! :)

Add to select.PNG

Now you can quickly add to dropdowns without having to leave the page.

If it's not exactly what you want you can use a similar approach by using jquery to modify things...


#1457 [ANSWERED] How to add fancybox in Grocery Crud

Posted KaBaDaBrA on 25 April 2012 - 04:48 PM

To make it so that when you click "add" to popup in fancybox

1. Ok edit "assets > grocery_crud > themes > flexigrid > list_template.php"

2. Add the following to the top: (change your url's as needed)

<link rel="stylesheet" href="<?=base_url()?>assets/plugins/fancybox/jquery.fancybox.css?v=2.0.6" type="text/css" media="screen" />
<script type="text/javascript" src="<?=base_url()?>assets/plugins/fancybox/jquery.fancybox.pack.js?v=2.0.6"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".various").fancybox();
});
</script>


3. Around line 45 - change the class from class="add-anchor" to class="various fancybox.ajax"

<a href='<?php echo $add_url?>' title='<?php echo $this->l('list_add'); ?> <?php echo $subject?>' class='various fancybox.ajax'>


4. I added my fancybox files under "assets > plugins > fancybox" - you can put yours wherever you want to I guess

test.PNG

I did all the above examples very quickly, but you can go further and customise various things im sure.... Coolios!!!!


#1456 [ANSWERED] How to add fancybox in Grocery Crud

Posted KaBaDaBrA on 25 April 2012 - 04:40 PM

@pinmouse - codeigniter anchor popup example:

1. You callback

$crud->callback_column('customerName', array($this, '_callback_name'));

2. Your functions


function test_content()
{
  echo 'BLARRRRP!!';

}

public function _callback_name($value, $row)
{
  $atts = array(
'width'	  => '500',
'height'	 => '500',
'scrollbars' => 'yes',
'status'	 => 'yes',
'resizable'  => 'yes',
'screenx'	=> '0',
'screeny'	=> '0'
);

return anchor_popup('examples/test_content', $value, $atts);
}

VOILA!!!! :D

Attached Thumbnails

  • popup.PNG



#1455 [ANSWERED] How to add fancybox in Grocery Crud

Posted KaBaDaBrA on 25 April 2012 - 04:28 PM

Aloha! :D

Quickly tested something and it worked hehe...

1. Ok edit "assets > grocery_crud > themes > flexigrid > list.php"
2. Add the following to the top: (change your url's as needed)

<link rel="stylesheet" href="<?=base_url()?>assets/plugins/fancybox/jquery.fancybox.css?v=2.0.6" type="text/css" media="screen" />
<script type="text/javascript" src="<?=base_url()?>assets/plugins/fancybox/jquery.fancybox.pack.js?v=2.0.6"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".fancybox").fancybox();
});
</script>

3. Add the callback to you controller function

$crud->callback_column('phone', array($this, '_callback_phone'));

4. Add the callback function


//FANCYBOX TEST
public function _callback_phone($value, $row)
{
  return "<a href='http://www.grocerycrud.com/assets/themes/default/images/logo.png' class='fancybox'>$value</a>";
}

5. I added my fancybox files under "assets > plugins > fancybox" - you can put yours wherever you want to I guess

capture.PNG

Voila! Should all work :D


#921 categories and subcategories

Posted KaBaDaBrA on 25 March 2012 - 03:42 PM

fleep!! Found a solution using the callback_add_field and callback_edit_field as per what web-johnny recommended too. At first I couldn't get the fancy dropdown boxes working but I managed to get it working!! :D

The callbacks:


$crud->callback_add_field('stateID', array($this, 'empty_state_dropdown_select'));
$crud->callback_edit_field('stateID', array($this, 'empty_state_dropdown_select'));
$crud->callback_add_field('cityID', array($this, 'empty_city_dropdown_select'));
$crud->callback_edit_field('cityID', array($this, 'empty_city_dropdown_select'));

The callback functions:


function empty_state_dropdown_select()
	{
	//CREATE THE EMPTY SELECT STRING
	$empty_select = '<select name="stateID" class="chosen-select" data-placeholder="Select State/Province" style="width: 300px; display: none;">';
	$empty_select_closed = '</select>';
	//GET THE ID OF THE LISTING USING URI
	$listingID = $this->uri->segment(4);

	//LOAD GCRUD AND GET THE STATE
	$crud = new grocery_CRUD();
	$state = $crud->getState();

	//CHECK FOR A URI VALUE AND MAKE SURE ITS ON THE EDIT STATE
	if(isset($listingID) && $state == "edit") {
	//GET THE STORED STATE ID
	$this->db->select('countryID, stateID')
		->from('customers')
		->where('customerNumber', $listingID);
	$db = $this->db->get();
	$row = $db->row(0);
	$countryID = $row->countryID;
	$stateID = $row->stateID;

	//GET THE STATES PER COUNTRY ID
	$this->db->select('*')
		->from('state')
		->where('countryID', $countryID);
	$db = $this->db->get();

	//APPEND THE OPTION FIELDS WITH VALUES FROM THE STATES PER THE COUNTRY ID
	foreach($db->result() as $row):
		if($row->state_id == $stateID) {
			$empty_select .= '<option value="'.$row->state_id.'" selected="selected">'.$row->state_title.'</option>';
		} else {
			$empty_select .= '<option value="'.$row->state_id.'">'.$row->state_title.'</option>';
		}
	endforeach;

		//RETURN SELECTION COMBO
		return $empty_select.$empty_select_closed;
	} else {
		//RETURN SELECTION COMBO
		return $empty_select.$empty_select_closed;
	}
}

function empty_city_dropdown_select()
{
	//CREATE THE EMPTY SELECT STRING
	$empty_select = '<select name="cityID" class="chosen-select" data-placeholder="Select City/Town" style="width: 300px; display: none;">';
	$empty_select_closed = '</select>';
	//GET THE ID OF THE LISTING USING URI
	$listingID = $this->uri->segment(4);

	//LOAD GCRUD AND GET THE STATE
	$crud = new grocery_CRUD();
	$state = $crud->getState();

	//CHECK FOR A URI VALUE AND MAKE SURE ITS ON THE EDIT STATE
	if(isset($listingID) && $state == "edit") {
	//GET THE STORED STATE ID
	$this->db->select('stateID, cityID')
		->from('customers')
		->where('customerNumber', $listingID);
	$db = $this->db->get();
	$row = $db->row(0);
	$stateID = $row->stateID;
	$cityID = $row->cityID;

	//GET THE CITIES PER STATE ID
	$this->db->select('*')
		->from('city')
		->where('stateID', $stateID);
	$db = $this->db->get();

	//APPEND THE OPTION FIELDS WITH VALUES FROM THE STATES PER THE COUNTRY ID
	foreach($db->result() as $row):
		if($row->city_id == $cityID) {
			$empty_select .= '<option value="'.$row->city_id.'" selected="selected">'.$row->city_title.'</option>';
		} else {
			$empty_select .= '<option value="'.$row->city_id.'">'.$row->city_title.'</option>';
		}
	endforeach;

		//RETURN SELECTION COMBO
		return $empty_select.$empty_select_closed;
	} else {
		//RETURN SELECTION COMBO
		return $empty_select.$empty_select_closed;
	}
}

If you have a big list like fleep does, the above code with force the two child dropdowns to load as an empty select instead of populating them from the start making the loading process muuuuch faster!!!


#917 categories and subcategories

Posted KaBaDaBrA on 25 March 2012 - 11:40 AM

I did the changes, but it's worse : page loading is twice longer as before.
And all the 36000 cities still appears in the source code :wacko:

I'll ask a friend of mine this afternoon, he might have the answer :)


Cool let me know...the only thing I can think of for now is getting GCRUD not to populate the states/cities on load but instead return a blank select :D


#830 add_action target _blank

Posted KaBaDaBrA on 18 March 2012 - 06:29 PM

can use jQuery to do it if there is no way on GCRUD yet...

Example:

$('#your_element_id').attr("target", "_blank");

EDIT: Just tested one of mine with the following:

$('a[title="Properties"]').attr("target", "_blank");

Works perfect - maybe they guys can add an additional option called "target" - something like the below. But until then jQuery can do sooooo much!!!!!

void add_action( string $label,  string $image_url , string $link_url , string $css_class ,  mixed $url_callback, string $target)



#827 categories and subcategories

Posted KaBaDaBrA on 18 March 2012 - 01:23 PM

I added in a loader image that displays next to the drop down as the child drop down loads.

Example here: http://demo.edynamic..._management/add

I also added it to the dynamic view example located in the downloaded file :)


#824 categories and subcategories

Posted KaBaDaBrA on 17 March 2012 - 08:30 PM

I tweaked the code a little and created a more dynamic and easier way to implement this instead of having to change the jQuery.

Add this to the top of the view:


//LOAD CRUD
$crud = new grocery_CRUD();
//SETUP DEPENDENT DROPDOWN
$dependent_dropdown = array(
//GET THE STATE OF THE CURRENT PAGE - E.G LIST | ADD
'state' =>  $crud->getState(),
//SETUP YOUR DROPDOWNS
//Parent field item always listed first in array, in this case countryID
//Child field items need to follow in order, e.g stateID then cityID
'dropdowns' => array('countryID','stateID','cityID'),
//SETUP URL POST FOR EACH CHILD
//List in order as per above
'url' => array('', site_url().'/examples/get_states/', site_url().'/examples/get_cities/')
);

Replace the Javascript at the bottom with the following:

if($dependent_dropdown['state'] == 'add' || $dependent_dropdown['state'] == 'edit')
//DONT HAVE TO EDIT THE CODE BELOW IF YOU DONT WANNA <img src='http://www.grocerycrud.com/forums/public/style_emoticons/default/tongue.png' class='bbc_emoticon' alt=':P' />
echo '$(document).ready(function() {';
for($i = 0; $i <= sizeof($dependent_dropdown['dropdowns'])-1; $i++):
//SET VARIABLES
echo 'var '.$dependent_dropdown['dropdowns'][$i].' = $(\'select[name="'.$dependent_dropdown['dropdowns'][$i].'"]\');';
//HIDE ALL CHILD ITEMS
if($i > 0 && $dependent_dropdown['state'] == 'add') {
  echo '$(\'#'.$dependent_dropdown['dropdowns'][$i].'_input_box\').hide();';
}
endfor;
for($i = 1; $i <= sizeof($dependent_dropdown['dropdowns'])-1; $i++):
//CHILD DROPDOWNS
echo $dependent_dropdown['dropdowns'][$i-1].'.change(function() {';
echo 'var select_value = this.value;';
//REMOVE ALL CURRENT OPTIONS FROM CHILD DROPDOWNS
echo $dependent_dropdown['dropdowns'][$i].'.find(\'option\').remove();';
//POST TO A CUSTOM CONTROLLER ADDING OPTIONS | JSON
echo 'var myOptions = "";';
//GET JSON REQUEST OF STATES
echo '$.getJSON(\''.$dependent_dropdown['url'][$i].'\'+select_value, function(data) {';
//APPEND RECEIVED DATA TO STATES DROP DOWN LIST
echo $dependent_dropdown['dropdowns'][$i].'.append(\'\');';
echo '$.each(data, function(key, val) {';
echo $dependent_dropdown['dropdowns'][$i].'.append(';
echo '$(\'\').val(val.value).html(val.property)';
echo ');';
echo '});';
//SHOW CHILD SELECTION FIELD
echo '$(\'#'.$dependent_dropdown['dropdowns'][$i].'_input_box\').show();';
//MAKE SURE CITY STILL HIDDEN INCASE OF COUNTRY CHANGE
for($x = $i+1; $x <= sizeof($dependent_dropdown['dropdowns'])-1; $x++):
  echo '$(\'#'.$dependent_dropdown['dropdowns'][$x].'_input_box\').hide();';
endfor;
//RESET JQUERY STYLE OF DROPDOWN LIST WITH NEW DATA
echo $dependent_dropdown['dropdowns'][$i-1].'.each(function(){';
echo '$(this).trigger("liszt:updated");';
echo '});';
echo $dependent_dropdown['dropdowns'][$i].'.each(function(){';
echo '$(this).trigger("liszt:updated");';
echo '});';
echo '});';
echo '});';
endfor;
echo '});';

The code that you pasted at the top you can change to your needs.

For example say you want to load up a cars list by make and model you would use something like this:

//LOAD CRUD
$crud = new grocery_CRUD();
//SETUP DEPENDENT DROPDOWN
$dependent_dropdown = array(
//GET THE STATE OF THE CURRENT PAGE - E.G LIST | ADD
'state' =>  $crud->getState(),
//SETUP YOUR DROPDOWNS
'dropdowns' => array('make_id','model_id'),
//SETUP URL POST FOR EACH CHILD
//List in order as per above
'url' => array('', site_url().'/examples/get_models/')
);

I added the dynamic example into the download - example (dynamic).php


#819 categories and subcategories

Posted KaBaDaBrA on 17 March 2012 - 11:39 AM

Impresive :) . I will add it to extra coding so other people can use it.


Awesome thanks man! I think this will help a lot of the guys struggling with dependent select boxes :)


#817 categories and subcategories

Posted KaBaDaBrA on 17 March 2012 - 10:23 AM

Hi there

I made a quick example / tutorial on how to create categories and subcategories by using jQuery. I based my example on Country -> State -> City

View / Download it here - click on "Add Customer" to see it in action.

Hope this all makes sense :D Feel free to ask me anything if you get stuck - if you're familiar with jQuery it's very easy.


#671 Successfully Install like a boss

Posted KaBaDaBrA on 04 March 2012 - 06:13 AM

+1

I have now added it to two of my projects successfully so far and working so well!!

Definitely have my support and hopefully the community will grow and give GROCERYCRUD some donations to help it grow even further!!! :)

GroceryCRUD  = :wub: