public function executeEdit(sfWebRequest $request) { $this->structures = $this->getRoute()->getObject(); $this->form = $this->configuration->getForm($this->structures); $this->json['success'] = true; $this->prepareJsonValues($this->form); $this->json['data'] = array_merge($this->json['data'], $this->FormJsonEncode()); $this->json['data'] = array_merge($this->json['data'], sfMmwExtjsUtil::getExtjsParamsfromArray('structures', $this->structures->getMatFinsAndFinitions())); if ($request->hasParameter('loadStores') && $request->getParameter('loadStores') == true) { $this->json['list'] = $this->FormRelationsJsonEncode(); } $this->setRequestParameter('json', $this->json); $this->forward($this->getModuleName(), 'jsonResponse'); }
protected function processForm(sfWebRequest $request, sfForm $form) { $formValues = array(); $requestParameters = $request->getParameterHolder()->getAll(); $formValues = sfMmwExtjsUtil::getSfParamsFromExtjs('identification', $requestParameters); $formValues = $this->prepareFormValues($formValues, $form); $files = $this->getSfFilesParamsFromExtjs($_FILES, 'identification'); //$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); $fieldsToPost = isset($requestParameters['fields']) ? json_decode($requestParameters['fields']) : null; foreach ($this->form->getWidgetSchema()->getFields() as $fieldname => $widget) { if (get_class($widget) != 'sfWidgetFormSchemaDecorator' && $fieldsToPost != null && !in_array(sfMmwExtjsUtil::getSfExtjsNameFromField('identification', $fieldname), $fieldsToPost)) { unset($form[$fieldname]); } } $form->bind($formValues, $files); if ($form->isValid()) { //$this->getUser()->setFlash('notice', $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.'); $this->json['success'] = true; $this->json['data'] = false; $identification = $form->save(); $this->prepareJsonValues($form); if (is_array($this->json['data'])) { $this->json['data'] = array_merge($this->json['data'], sfMmwExtjsUtil::getExtjsParamsfromArray('identification', $identification->toArray())); } else { $this->json['data'] = sfMmwExtjsUtil::getExtjsParamsfromArray('identification', $identification->toArray()); } $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $identification))); } else { //$this->getUser()->setFlash('error', 'The item has not been saved due to some errors.'); $this->json['success'] = false; $this->json['data'] = false; if ($form->hasErrors()) { $this->json['errormsg'] = 'Data has not been saved'; // set individual error field foreach ($form->getErrorSchema() as $field => $error) { $this->json['errors'][sfMmwExtjsUtil::getSfExtjsNameFromField('identification', $field)] = $error->getMessage(); } } } // SURCHARGE $secteurCommune = $identification->getSecteurCommune(); if (!empty($secteurCommune)) { $this->json['data']['identification__secteur'] = $secteurCommune; } $this->json['list'] = $this->FormRelationsJsonEncode(); // FIN SURCHARGE $this->setRequestParameter('json', $this->json); $this->forward($this->getModuleName(), 'jsonResponse'); }