• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] CI + XAJAX Global Functions

#8
[eluser]LifeSteala[/eluser]
I've included the JavaScript. I register the functions in the controllers constructor. Here's my controller.

Code:
class Entertime extends MY_Controller
{
    function Entertime()
    {
        parent::MY_Controller();
        
        $this->load->model('timesheets');
        $this->load->model('clients');
        $this->load->model('projects');
        $this->load->model('tasks');
        
        $this->load->library(array('validation', 'xajax', 'globalajax'));
        
        $this->load->helper('url');
        $displayoutput = "";
        $type = "";
        $name = "";
        $status = "";
    }
    
    
    function index()
    {

        $this->xajax->registerFunction(array('get_projects',&$this,'get_projects'));
        $this->xajax->registerFunction(array('get_tasks',&$this,'get_tasks'));
        $this->xajax->registerFunction(array("auto_suggest", &$this, "auto_suggest"));
        $this->xajax->processRequest();
        $data['xajax_js'] = $this->xajax->getJavascript(base_url());
                
                // More code here
        }
}

Here's my library

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

    class Globalajax
    {
    
        function Globalajax()
        {
            log_message('debug', "Global Ajax Functions Class Initialized");
        }

        // Function: get_projects - Public
        // Gets projects depending on what client is selected. AJAX
        //-----------------------------------------------------------------------------------------------
        function get_projects($clientName)
        {
            $proj_query = $this->projects->getProjectsAjaxSearch($clientName);
            
            $output = '<label for="project">Project: </label>';
            $output .= "<select name=\"project\">\n";
            
            if ( $proj_query->num_rows() > 0 ) {
                $output .= '<option selected="selected"></option>';
                
                foreach($proj_query->result() as $rows)
                    $output .= "<option value=\"{$rows->project_id}\">{$rows->project_name}</option>";
            }
            else
                $output .= '<option selected="selected">No projects available</option>';
            
            $output .= '</select>';
            
            $objResponse = new xajaxResponse();
            $objResponse->Assign("optionProjects","innerHTML", $output);
            return $objResponse;
        }
    
        // Function: get_tasks - Public
        // Gets tasks depending on what project is selected. AJAX
        //-----------------------------------------------------------------------------------------------
        function get_tasks($projectID)
        {
            $task_query = $this->tasks->getTasksAjax($projectID);
            
            $output = '<label for="task">Task: </label>';
            $output .= '<select name="task">\n';
            
            if ( $task_query->num_rows() > 0 ) {
                $output .= '<option selected="selected"></option>';
                
                foreach($task_query->result() as $rows)
                    $output .= "<option value=\"{$rows->task_id}\">{$rows->task_name}</option>";
            }
            else
                $output .= '<option selected="selected">No tasks created</option>';
            
            $output .= '</select>';
            
            $objResponse = new xajaxResponse();
            $objResponse->Assign("optionTasks","innerHTML", $output);
            return $objResponse;
        }
        
        // Function: get_tasks - Public
        // Gets tasks depending on what project is selected. AJAX
        //-----------------------------------------------------------------------------------------------
        function auto_suggest($val)
        {
            $objResponse = new xajaxResponse();
    
            $result = "";
    
            if (isset($val) && $val != "")
            {
                $query = $this->clients->searchClients($val);
    
                if ($query->num_rows() > 0) {
                    foreach ($query->result() as $row) {
                        $result .= "<div title='". $row->client_name . "' onmouseover='[removed]suggest_over(this);'";
                        $result .= " onmouseout='[removed]suggest_out(this);'";
                        $result .= " onclick='[removed]set_search(this.title);' class='suggest_link'>";
                        $result .= $row->client_name;
                        $result .= "</div>";
                    }
    
                    $objResponse->Assign("client_result", "style.display", 'block');
                    $objResponse->Assign("client_result", "innerHTML", $result);
                }    else {
                    $objResponse->Assign("client_result", "style.display", 'none');
                }
            }    else {
                $objResponse->Assign("client_result", "style.display", 'none');
            }
    
            return $objResponse;
        }
    }
?&gt;


Messages In This Thread
[Solved] CI + XAJAX Global Functions - by El Forum - 08-07-2008, 05:56 PM
[Solved] CI + XAJAX Global Functions - by El Forum - 08-07-2008, 07:05 PM
[Solved] CI + XAJAX Global Functions - by El Forum - 08-07-2008, 07:53 PM
[Solved] CI + XAJAX Global Functions - by El Forum - 08-07-2008, 08:26 PM
[Solved] CI + XAJAX Global Functions - by El Forum - 08-07-2008, 08:37 PM
[Solved] CI + XAJAX Global Functions - by El Forum - 08-07-2008, 09:00 PM
[Solved] CI + XAJAX Global Functions - by El Forum - 08-07-2008, 09:04 PM
[Solved] CI + XAJAX Global Functions - by El Forum - 08-07-2008, 09:13 PM
[Solved] CI + XAJAX Global Functions - by El Forum - 08-07-2008, 09:41 PM
[Solved] CI + XAJAX Global Functions - by El Forum - 08-07-2008, 09:46 PM
[Solved] CI + XAJAX Global Functions - by El Forum - 10-11-2008, 12:30 AM
[Solved] CI + XAJAX Global Functions - by El Forum - 10-12-2008, 02:10 PM
[Solved] CI + XAJAX Global Functions - by El Forum - 10-12-2008, 11:07 PM
[Solved] CI + XAJAX Global Functions - by El Forum - 10-12-2008, 11:17 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.