Skip to content

Commit

Permalink
Merge pull request #1 from olegabr/master
Browse files Browse the repository at this point in the history
debugged version
  • Loading branch information
olegabr committed Jul 14, 2016
2 parents ae0b9dc + d4d53c1 commit b07d771
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
16 changes: 13 additions & 3 deletions examples/signaturepad.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,25 @@ class SampleForm extends QForm {

protected function Form_Create() {
$this->txtSignaturePad1 = new QSignaturePad($this);
$this->txtSignaturePad1->Clear();
$this->lblImageLink = new QLabel($this);
$this->lblImageLink->Name = QApplication::Translate("Image data");
$this->btnClear = new QButton($this);
$this->btnClear->Name = QApplication::Translate("Clear");
$this->btnClear->Text = QApplication::Translate("Clear");
$this->btnClear->AddAction(new QClickEvent, new QAjaxAction("btnClear_Click"));
$this->btnSave = new QButton($this);
$this->btnSave->Name = QApplication::Translate("Save");
$this->btnSave->Text = QApplication::Translate("Save");
$this->btnSave->AddAction(new QClickEvent, new QAjaxAction("btnSave_Click"));
}
}

public function btnClear_Click($strFormId, $strControlId, $strParameter) {
$this->txtSignaturePad1->Clear();
$this->lblImageLink->Text = "";
}

public function btnSave_Click($strFormId, $strControlId, $strParameter) {
$this->lblImageLink->Text = $this->txtSignaturePad1->Data;
}
}

SampleForm::Run('SampleForm');
Expand Down
22 changes: 14 additions & 8 deletions includes/QSignaturePadGen.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,34 @@
* @property string $Data The data:image/png;base64 image data
*/
namespace QCubed\Plugin;
use \QType, \QApplication, \QInvalidCastException, \QCallerException;
use \QType, \QApplication, \QInvalidCastException, \QCallerException, \QBlockControl;

class QSignaturePadGen extends QBlockControl {
/** @var string HTML tag to be used by the control (such as div or span) */
protected $strTagName = 'canvas';
/**
* @var string The data:image/png;base64 image data
*/
protected $strData;

protected function getJsObjectString() {
$strControlId = $this->ControlId;
$strId = "SignaturePad_" . $this->ControlId;
$strId = "SignaturePad_" . $strControlId;
$strCode = <<<JS
((function(){
if ("undefined" === typeof window["$strId"]) {
var canvas = document.getElementById("$strId");
var signaturePad = new SignaturePad(canvas);
window["$strId"] = signaturePad;
var id = "$strId";
if ("undefined" === typeof window[id]) {
var canvas = document.getElementById("$strControlId");
var signaturePad = new SignaturePad(canvas, {backgroundColor: "rgb(255,255,255)"});
window[id] = signaturePad;
signaturePad.onEnd = function() {
qcubed.recordControlModification("$strControlId", "_Value", window["$strId"].toDataURL());
qcubed.recordControlModification("$strControlId", "_Value", window[id].toDataURL());
}
}
return window["$strId"];
return window[id];
})())
JS;
return $strCode;
}

protected function ExecuteFunction($strFunctionName /*, ... */) {
Expand Down

0 comments on commit b07d771

Please sign in to comment.