Skip to content

Commit

Permalink
Merge pull request #7 from spekary/master
Browse files Browse the repository at this point in the history
bugfix-AjaxTextUpdate
  • Loading branch information
olegabr committed May 21, 2016
2 parents 700694d + d0a2fdc commit c4f6657
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
11 changes: 11 additions & 0 deletions control_registry.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

/**
* Called by the ModelConnector Designer to create a list of controls appropriate for the given database field type.
* The control will be available in the list of controls that appear in ModelConnector desginer dialog
* in the ControlClass entry.
*/

$controls[QControlCategoryType::Blob][] = 'QCubed\Plugin\QCKEditor';
$controls[QControlCategoryType::Text][] = 'QCubed\Plugin\QCKEditor';

14 changes: 13 additions & 1 deletion examples/ckeditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@

class SampleForm extends QForm {
protected $txtEditor;
protected $btnSubmit;
protected $pnlResult;

protected function Form_Create() {
$this->txtEditor = new QCKEditor($this);
$this->txtEditor->Text = '<b>Something</b> to start with.';

$this->btnSubmit = new QButton($this);
$this->btnSubmit->Text = "Submit";
$this->btnSubmit->AddAction(new QClickEvent(), new QAjaxAction('submit_click'));

$this->pnlResult = new QPanel($this);
$this->pnlResult->HtmlEntities = true;
}

protected function submit_click($strFormId, $strControlId, $param) {
$this->pnlResult->Text = $this->txtEditor->Text;
}
}

SampleForm::Run('SampleForm');
?>
3 changes: 3 additions & 0 deletions examples/ckeditor.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
to create a text editing block with full HTML editing capabilities. The text returned from it is HTML.
</p>
<?php $this->txtEditor->Render(); ?>
<?php $this->btnSubmit->Render(); ?>
<h3>The HTML you typed:</h3>
<?php $this->pnlResult->Render(); ?>
</div>

<?php $this->RenderEnd(); ?>
Expand Down
13 changes: 11 additions & 2 deletions includes/QCKEditorBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ public function getJqSetupFunction() {

// currently cannot use ajax
public function GetControlJavaScript() {
return sprintf('jQuery("#%s").%s(%s)', $this->getJqControlId(), $this->getJqSetupFunction(), $this->strJsReadyFunc);
$strFormId = $this->Form->FormId;
$strControlId = $this->strControlId;
$strReadyFunc = 'null';
if ($this->strJsReadyFunc) {
$strReadyFunc = $this->strJsReadyFunc;
}
$strJs = "function() {qcubed.qckeditor(this, '{$strFormId}', '{$strControlId}', {$strReadyFunc});}";
return sprintf('jQuery("#%s").%s(%s)', $this->getJqControlId(), $this->getJqSetupFunction(), $strJs);
}

public function GetEndScript() {
Expand All @@ -40,7 +47,9 @@ public function __set($strName, $mixValue) {

//$this->blnModified = true;
switch ($strName) {
case "ReadyFunction": // The name of a javascript function to call after the CKEditor instance is ready, so that you can do further initialization
case "ReadyFunction":
// The name of a javascript function to call after the CKEditor instance is ready, so that you can do further initialization
// This function will receive the formId and controlId as parameters, and "this" will be the ckeditor instance.
try {
$this->strJsReadyFunc = QType::Cast($mixValue, QType::String);
break;
Expand Down
20 changes: 18 additions & 2 deletions js/QCKSetup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
// CKEditor Setup Functions

// Must be path to ckeditor relative to DOCROOT
var CKEDITOR_BASEPATH = qc.baseDir + "/vendor/ckeditor/ckeditor/";
// Must be path to ckeditor relative to DOCROOT
var CKEDITOR_BASEPATH = qc.baseDir + "/vendor/ckeditor/ckeditor/";

// Insert a custom startup function into qcubed to help us retrieve data during ajax calls.
qcubed.qckeditor = function (inst, formId, controlId, customReadyFunc) {
// We need to do this on the qposting event because blur and change are delayed and fire after button events.
$j('#' + formId).on('qposting', function() {
if (inst.checkDirty()) { // provided by ckeditor
// This works because the jquery adapter provides a .val() function, which is what qcubed.js uses
// We could also call qcubed.setAdditionalPostVar here
$j('#' + controlId).change();
}
});

if (customReadyFunc) {
customReadyFunc.call(inst, formId, controlId);
}
};

0 comments on commit c4f6657

Please sign in to comment.