_messageTemplates['msgNotDeleted'] = '%itemName% not deleted'; $this->_messageTemplates['msgNotUpdated'] = '%itemName% not updated'; $this->_messageTemplates['msgDenyEdit'] = 'You can not edit this %itemName%'; parent::_init(); $defaultAction = $this->getConfig('defaultAction'); if (!empty($defaultAction)) { $this->_defaultAction = $defaultAction; } $this->_editPageAlias = Qs_SiteMap::findFirst( null, array('type' => 'SchoolFile_'), array('defaultAction' => 'new'), 'fullAlias' ); if ($this->doc) { $this->_userIdentity = $this->doc->getAuth()->getIdentity(); } $this->dataObj->addFilter(array('enabledSubject' => 'y')); return $this; } protected function _initFromForm($form) { $data = $form->getValues(); if ($data['type'] == 'strand') { unset($data['idLessonType'], $data['title']); } $data['idSchool'] = $this->_userIdentity['data']['idSchool']; $data['idUser'] = $this->_userIdentity['data']['id']; $this->dataObj->initFromForm($data); return $this; } protected function _getDefaultLinks() { return array(); } protected function _bindFormFields($form) { parent::_bindFormFields($form); $form->removeElement('otherSchool'); $form->removeElement('idSchool'); $form->removeElement('otherSchoolName'); $form->removeElement('sourceContact'); return $this; } public function validateForm($data) { $errors = array(); if ($data['idLessonType'] == 2 && $data['summativeAssessmentNumber'] == 0) { $errors['summativeAssessmentNumber'] = "Value is required and can't be empty"; } return (empty($errors)) ? true : $errors; } protected function _bindListColumns($list) { parent::_bindListColumns($list); $list->removeColumn('no'); $list->removeColumn('sourceContact'); //$file = $list->getColumn('file'); //$file['template'] = $this->getTemplate('cells/text.tpl'); //$list->updateColumn('file', $file); $options = $list->getColumn('options'); $options['actions']['edit']['link'] = BASE_URL . '/' . $this->_editPageAlias . '?action=edit'; $list->updateColumn('options', $options); $list->columnMove('grade', -2); $list->columnMove('subject', -2); $list->columnMove('lessonType', -1); return $this; } protected function _checkUser($msgConstant) { $data = $this->dataObj->getData(); if (empty($data) || empty($this->_userIdentity) || $data['idUser'] != $this->_userIdentity['data']['id']) { $this->_setBackError($msgConstant); $this->_doBack(); } return $this; } protected function _doDelete() { $this->_checkUser(self::MSG_NOT_DELETED); return parent::_doDelete(); } protected function _doUpdateAjax() { $this->_checkUser(self::MSG_NOT_UPDATED); return parent::_doUpdateAjax(); } protected function _doUpdate() { $this->_checkUser(self::MSG_NOT_UPDATED); return parent::_doUpdate(); } protected function _doEdit() { $this->_checkUser(self::MSG_DENY_EDIT); return parent::_doEdit(); } protected function _bindFormButtons($form) { $form->addElement('submit', 'btnSubmit', array( 'label' => 'Upload', 'attribs' => array('class' => 'buttons'), 'decorators' => array('ViewHelper') ) ); //$form->btnSubmit->getDecorator('ViewHelper')->setAdditionalHtmlAfterElement('  '); //$btnCancel = new Zend_Form_Element_Button('btnCancel', // array( // 'label' => 'Cancel', // 'attribs' => array( // 'class' => 'btn', // 'onclick' => "document.location = '{$form->getCancelUrl()}';" // ), // 'decorators' => array('ViewHelper') // ) //); //$form->addElement($btnCancel); $decorators = array('FormElements'); $decorators[] = array('decorator' => 'HtmlTag', 'options' => array('tag' => 'div')); $decorators[] = 'Fieldset'; $decorators[] = 'DtDdWrapper'; $form->addDisplayGroup(array('btnSubmit'/*, 'btnCancel'*/), 'submitGroup', array('decorators' => $decorators)); return $this; } protected function _doList() { //$this->_saveBackUrl(); $this->_setBackUrl(Qs_Request::getUrl(), $this->_editPageAlias); $this->_addFilterItem(); $this->_addLinksItem(); $this->_addListItem(); } public function fillConfigForm($form) { $actions = array( 'list' => 'Lessons and Assessments List', 'new' => 'Upload Lesson or Assessment', ); $form->addElement( 'select', 'defaultAction', array('label' => 'Default Action', 'required' => true, 'multiOptions' => $actions) ); return $this; } protected function _bindFilterFields($form) { $this->doc->addScript('js/jquery.poshytip.js'); $this->doc->addScript('js/app/school-file-hints.js'); //$this->doc->addStylesheet('css/tip/tip-yellow/tip-yellow.css'); $this->doc->addStylesheet('css/tip/tip-yellowsimple/tip-yellowsimple.css'); $this->doc->addInitFunction('initSchoolFileHints'); parent::_bindFilterFields($form); $qTipHtml = '
' . '' . '
%s
' . '
'; $qTipElements = array( 'grade' => 'filterHintsGrade', 'idSubject' => 'filterHintsSubject', 'idLessonType' => 'filterHintsLesson', 'idSchool' => 'filterHintsSchool', ); foreach ($qTipElements as $name => $settingName) { $form->{$name}->getDecorator('ViewHelper')->setAdditionalHtml( array('AfterElement' => sprintf($qTipHtml, App_Settings_Obj::get($settingName))) ); } $form->removeElement('query'); $form->addElement('hidden', 'query', array('value' => '')); return $this; } protected function _bindFilterButtons($form) { $form->addElement( 'submit', 'btnSearch', array( 'label' => 'Filter', 'ignore' => true, 'attribs' => array('class' => 'btn'), 'decorators' => array('ViewHelper') ) ); $form->addElement( 'button', 'btnCancel', array( 'label' => 'Reset Filter', 'ignore' => true, 'decorators' => array('ViewHelper'), 'attribs' => array( 'class' => 'btn', 'onclick' => "document.location='" . BASE_URL . '/' . CURRENT_PAGE . "';", ) ) ); $decorators = array('FormElements'); $decorators[] = array('decorator' => 'HtmlTag', 'options' => array('tag' => 'dl')); $decorators[] = 'Fieldset'; $form->addDisplayGroup(array('btnSearch', 'btnCancel'), 'submitGroup', array('decorators' => $decorators)); } protected function _addFilterItem() { parent::_addFilterItem(); $this->_addItem(array( 'tpl' => $this->getTemplate('filter-small.tpl'), 'query' => $this->dataObj->getFilter('query'), )); return $this; } }