Domanda

In my site, i have a page which is intended to handle a basic ticket system for bug tracking and feature requests. I need a grid to be displayed of the currently open requests with a button which allows the user to add new ones. I also want each row to have a button called 'detail' which will either open a new page or popup a frame (dont mind which) containing the history e.g. the dates, times and any commments that the bug/issue has had, status updates or comments and a simple form to allow the user to add new responses.

So far, I create a page to which i added a CRUD and used addColumn('button','detail') to add a button to each row.

enter image description here

and the ATK4 code to create this is elegantly short like this

 <?php
  class page_ticket extends Page {
     function init() {
     parent::init();
     $p=$this;

     $team=$this->api->getTeamID();

     if (isset($_GET['detail'])) {
       $ticket=$_GET['detail'];
       $p->add('HtmlElement',null, 'crud')->setElement('h2')->set('Ticket History - ['.$ticket.']');
     } else {

       $tk=$p->add('CRUD_Ticket', null, 'crud');
       $m=$tk->setModel('Ticket', array('name', 'submit_date', 'status','ticket_type_id', 'urgency_id','description');

       $m->addCondition('status','TKO');

       $open=$this->api->db->dsql()->table('vscrum_ticket')
                  ->field('count(*)')
                  ->where('team_id',$team)
                  ->where('status','TKO')
                  ->do_getOne();
       ..   ..   ..

       $tk->grid->addQuickSearch(array('name'));
       $tk->grid->addPaginator(12);
  }

  $this->template->set('open_tickets', $open);
 } //End else detail
}

function defaultTemplate(){
    return array('page/ticket');
}

}

But the problem is i cant work out where the default functionality of the button is handled. At the moment, it will by default open the same page (ticket.php) passing the parameter but what happens is it opens a new window and gives an Ajax error as shown.

enter image description here

I have included an if then else in the page and in the error window, it displays my output correctly which is the Ticket ID of the row where the detail button was pressed. I can add the other detail later but why is it opening this in a new window instead of loading it in the frame ?

I assume it's the default functionality of the CRUD as the buttons are normally edit or delete but how can i override this ?

If i wanted to open a different page, rather than the same one, i assume this would also be related to overriding the default functionality of the MVCGrid buttons which opens a frame using the javascript frameURL function.

The CRUD looks like this

  <?php
class CRUD_Ticket extends View {
    public $form=null;
    public $grid=null;

    public $grid_class='MVCGrid';
    public $form_class='MVCForm';

    public $frame_options=null;
    function init(){
    parent::init();

    if(isset($_GET[$this->name])){
        $this->api->stickyGET($this->name);

        $this->form=$this->add($this->form_class);
        $_GET['cut_object']=$this->name;

        return;
    }

    $this->grid=$this->add($this->grid_class);
    $this->js('reload',$this->grid->js()->reload());
    $this->add_button = $this->grid->addButton('Add Ticket');
    $this->add_button->js('click')->univ()
        ->frameURL('Add Ticket',$this->api->getDestinationURL(null,array($this->name=>'new')),$this->frame_options);

    }

    function setModel($a,$b=null){
    if($this->form){
        $m=$this->form->setModel($a,$b);

        if(($id=$_GET[$this->name])!='new'){
        $m->loadData($id);
        }

        if($this->form->isSubmitted()){
        $this->form->update(); 
                    $this->form->js(null,$this->js()
                         ->trigger('reload'))->univ()->closeDialog()->execute();
        }
        return $m;
    }
    $m=$this->grid->setModel($a,$c);

    $this->grid->addColumn('button','detail');
    if($id=@$_GET[$this->grid->name]){
        $this->js()->univ()->frameURL('Ticket History',$this->api->getDestinationURL(
                    null,array($this->name=>$id)))->execute();
    }
    return $m;
    }
}

I tried changing the call to frameURL to in the CRUD to

   $this->js()->univ()->page('ticketdtl',array($this->name=>$id)); 

and

   $this->js()->univ()->location($this->api->getDestinationURL('tktdetail',array($this->name=>$id))

but these also dont work as it still redirects to the original page so i think it must be default functionality that needs overriding somewhere - just cant figure out where ?

Went back to the agiletoolkit.org page here and realised that the demo where button is added to the Grid (B1 & B2) also exhibit same behaviour.

È stato utile?

Soluzione

The buttons in Agile Toolkit Grid send a request asking for some JavaScript response. When that response arrives, it can open a frame. As a result you need to do two requests instead of one.

I have included a working example here:

http://agiletoolkit.org/codepad/gui/grid#GridButton

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top