<?
class frmDragDrop1 extends MForm
{
    public function __construct()
    {
        parent::__construct("Drag&Drop - Sample 1");
        $this->eventHandler();
    }

    public function createFields()
    { 
        $ui = $this->manager->getUI();
        $this->page->addStyleCode(".dropHover {background-color: #EEE}");

        $drag1 = new MDiv('drag1','Sample text');
        $drag1->width = '100px';
        $drag1->backgroundColor = 'red';
        $drag1->margin = '10px';

        $drag2 = new MImage('drag2','',$ui->getImage('','button_refresh.png'));
        $drag2->margin = '10px';

        $drag3 = new MDiv('drag3','Another text');
        $drag3->width = '100px';
        $drag3->backgroundColor = 'blue';

        $source = new MBaseGroup('dragBox',"Drag from Here",array($drag1,$drag2, $drag3));
        $boxSource = new MDiv('boxSource',array($labelSource, $source));

        $drop1 = new MDiv('dropBox1');
        $drop1->border = "1px #000";
        $drop1->height = '100px';
        $drop1->width = '100px';
        $drop1->backgroundColor = '#ddd';
        $labelTarget1 = new MLabel("Drop AnyThing Here - 1");
        $boxTarget1 = new MDiv('boxTarget1',array($labelTarget1, $drop1));

        $drop2 = new MDiv('dropBox2');
        $drop2->border = "1px #000";
        $drop2->height = '100px';
        $drop2->width = '100px';
        $drop2->backgroundColor = '#ddd';
        $labelTarget2 = new MLabel("Drop AnyThing Here - 2");
        $boxTarget2 = new MDiv('boxTarget2',array($labelTarget2, $drop2));

        $dd = new MDragDrop('dd1');
        $dd->addDraggable($source);
        $dd->addDropZone($drop1);
        $dd->addDropZone($drop2);

        $status = new MDiv('divText');

        $fields = array(
            $boxSource,
            new MHContainer('',array($boxTarget1,new MDiv('','&nbsp;'), $boxTarget2)),
            $dd,
            array(new MLabel('Status:'),$status)
        );
        $this->setFields($fields);
        
        $buttons = array(
            new MButton(btnPost,'Enviar')
        );
        $this->setButtons($buttons);
    }

    public function btnPost_click()
    {
        $v = $this->dd1->getValue();
        foreach($v as $drag=>$drop)
        {
           $dd[] = array($drag,$drop);
        }
        $this->addField(new MTableRaw('Results',$dd,array('Element dragged','& dropped on')));
    }

}
?>
