Custom Plugin works with QServer not with QAjax

Login or register to post comments
3 replies [Last post]
Offline
Joined: 11/23/2008

Hi folks,

i'm working on a qcubed plugin (QProgressBar) which will make use of jquery progress bar.
the plugin works good with QServer but i can't make it goes with QAjax mode here's the class

<?php

class QProgressBar extends QControl  {

    protected
$intValue;
    public function
__construct($objParentObject, $strControlId = null) {
        if (
$objParentObject) {
           
parent::__construct($objParentObject, $strControlId);
        }
       
$this->setFiles();
    }

    private function
setFiles() {
       
$this->AddJavascriptFile(__JQUERY_BASE__);
       
$this->AddPluginJavascriptFile("QProgressBar", "jquery.ui.core.js");
       
$this->AddPluginJavascriptFile("QProgressBar", "jquery.ui.widget.js");
       
$this->AddPluginJavascriptFile("QProgressBar", "ui.progress.js");
       
$this->AddPluginCssFile("QProgressBar", "progressbar.css");
       
/*if (QApplication::IsBrowser(QBrowserType::InternetExplorer)) {
            $this->AddPluginCssFile("QProgress", "Progress_ie.css");
            }*/
   
}

    protected function
GetControlHtml() {
       
$strHtml = sprintf('<div id="progress_%s" class="%s"></div>',
       
$this->ControlId,
       
$this->CssClass);
       
$this->intValue = ($this->intValue) ? $this->intValue : 0;
       
$strJsProgress = sprintf('
            $(document).ready(function(){       
           
            $("#progress_%s").progressbar({ value:%s});
           
            $("#progress_%s").progressbar( "option", "value", %s );
            
            });'
,
       
$this->ControlId,
       
$this->intValue,
       
$this->ControlId,
       
$this->intValue);
           
       
QApplication::ExecuteJavaScript($strJsProgress);
        return
$strHtml ;
    }

    public function
GetEndScript() {
        return
null;
    }

    public function
ParsePostData() {
        return
true;
    }

    public function
Validate(){
        return
true;
    }

    public function
__get($strName) {
        switch (
$strName) {
           
// APPEARANCE
           
case "Value":
                return
$this->intValue;
            default:
                try {
                    return
parent::__get($strName);
                } catch (
QCallerException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }
        }
    }

    public function
__set($strName, $mixValue) {
        switch (
$strName) {
           
// APPEARANCE
           
case "Value":
                try {

                   
$this->intValue = QType::Cast($mixValue, QType::Float);
                    break;
                } catch (
QInvalidCastException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }
            default:
                try {
                   
parent::__set($strName, $mixValue);
                } catch (
QCallerException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }
                break;
        }
    }
}
?>

Any help will be much appreciated as soon as this is fixed i'll clean the code and contribute the plugin.

Thanks

Kent

Offline
Joined: 11/23/2008

Hello again,

does anyone has made a plugin working with QAjax request mode ?

Thanks again

Offline
Joined: 03/31/2008

My guess is that this uses js to update the progress bar. This will work with server actions because every post-back causes document.ready to get triggered again. But with Ajax, .ready isn't triggered a second time, so your update js never runs.

Perhaps you need an ExecuteJavascript that doesn't involve document.ready in the case of Ajax callbacks?

Offline
Joined: 11/23/2008

Nice point vexed,

i'll try this and let you know

thx