A QCodo powered CMS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
3.9 KiB

  1. <?php
  2. //TODO: Autoload me ..
  3. require(__QUINTA_CONTRIB_CONTROLLERS__ . '/QFileInput.class.php');
  4. /**
  5. * This class provides a dialog pop-up for uploading files.
  6. *
  7. *@author Erik Winn <sidewalksoftware@gmail.com>
  8. *
  9. *@version 0.1
  10. *
  11. * @package QuintaContrib
  12. * @subpackage Classes
  13. */
  14. class QFileInputDialog extends QDialogBox
  15. {
  16. public $ctlFileInput;
  17. public $lblErrorMessage;
  18. public $btnUpload;
  19. public $btnCancel;
  20. public $objSpinner;
  21. protected $objParentObject;
  22. protected $strFileUploadCallback;
  23. public function __construct($objParentObject, $strFileUploadCallback, $strControlId = null){
  24. $this->objParentObject = $objParentObject;
  25. try {
  26. parent::__construct($this->objParentObject, $strControlId);
  27. } catch (QCallerException $objExc) {
  28. $objExc->IncrementOffset();
  29. throw $objExc;
  30. }
  31. $this->strFileUploadCallback = $strFileUploadCallback;
  32. $this->strTemplate = __QUINTA_CONTRIB_VIEWS__ . '/QFileInputDialog.tpl.php';
  33. $this->blnDisplay = false;
  34. $this->blnMatteClickable = false;
  35. $this->lblErrorMessage = new QLabel($this);
  36. $this->lblErrorMessage->HtmlEntities = false;
  37. $this->ctlFileInput = new QFileInput($this);
  38. $this->btnUpload = new QButton($this);
  39. $this->btnUpload->Text = QApplication::Translate('Upload');
  40. $this->btnUpload->CausesValidation = QCausesValidation::SiblingsOnly;
  41. $this->btnCancel = new QButton($this);
  42. $this->btnCancel->Text = QApplication::Translate('Cancel');
  43. $this->objSpinner = new QWaitIcon($this);
  44. // Events on the Dialog Box Controls
  45. $this->ctlFileInput->AddAction(new QEnterKeyEvent(), new QTerminateAction());
  46. $this->btnUpload->AddAction(new QClickEvent(), new QToggleEnableAction($this->btnUpload));
  47. $this->btnUpload->AddAction(new QClickEvent(), new QToggleEnableAction($this->btnCancel));
  48. $this->btnUpload->AddAction(new QClickEvent(), new QToggleDisplayAction($this->objSpinner));
  49. $this->btnUpload->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnUpload_Click'));
  50. $this->btnCancel->AddAction(new QClickEvent(), new QHideDialogBox($this));
  51. }
  52. /* fixme - figure out how to call this ..
  53. public function Validate()
  54. {
  55. $this->strValidationError = "";
  56. if ($this->ErrorCode != 0)
  57. {
  58. $this->strValidationError = $this->ErrorMessage;
  59. return false;
  60. }
  61. if (! $this->blnRequired )
  62. return true;
  63. if (strlen($this->strFileName) > 0)
  64. return true;
  65. if(strlen( $this->Name ))
  66. $this->strValidationError = _t($this->strName) . ' ' . _t('is required');
  67. else
  68. $this->strValidationError = "Filename is required";
  69. return false;
  70. }*/
  71. public function btnUpload_Click($strFormId, $strControlId, $strParameter)
  72. {
  73. $this->btnUpload->Enabled = true;
  74. $this->btnCancel->Enabled = true;
  75. $this->objSpinner->Display = false;
  76. $strFileControlCallback = $this->strFileUploadCallback;
  77. $this->objParentControl->$strFileControlCallback($strFormId, $strControlId, $strParameter);
  78. }
  79. public function ShowErrorMessage($strErrorMessage=null)
  80. {
  81. if( null !== $strErrorMessage)
  82. $this->lblErrorMessage->Text = $strErrorMessage;
  83. else
  84. $this->lblErrorMessage->Text = $this->ErrorMessage;
  85. $this->ctlFileInput->Focus();
  86. $this->Blink();
  87. }
  88. public function __get($strName)
  89. {
  90. switch ($strName)
  91. {
  92. case 'TempUri':
  93. return $this->ctlFileInput->TempUri;
  94. case 'FileName':
  95. return $this->ctlFileInput->FileName;
  96. case 'Extension':
  97. return $this->ctlFileInput->Extension;
  98. case 'Size':
  99. return $this->ctlFileInput->Size;
  100. case 'MimeType':
  101. return $this->ctlFileInput->MimeType;
  102. case 'ErrorCode':
  103. return $this->ctlFileInput->ErrorCode;
  104. case 'ErrorMessage':
  105. return $this->ctlFileInput->ErrorMessage;
  106. default:
  107. try {
  108. return parent::__get($strName);
  109. } catch (QCallerException $objExc) {
  110. $objExc->IncrementOffset();
  111. throw $objExc;
  112. }
  113. }
  114. }
  115. }
  116. ?>