Exemple #1
0
 public function saveInto($record)
 {
     $data = $this->form->getRecord();
     // if the record was written for the first time (has an arbitrary "new"-ID),
     // update the imagefield to enable uploading
     if ($record->ID && $data && substr($data->ID, 0, 3) == 'new') {
         FormResponse::update_dom_id($this->id(), $this->Field($record->ID));
     }
 }
	/**
	 * Returns the content of the TableListField as a piece of FormResponse javascript
	 * @deprecated Please use the standard URL through Link() which gives you the FieldHolder as an HTML fragment.
	 */
	function ajax_refresh() {
		// compute sourceItems here instead of Items() to ensure that
		// pagination and filters are respected on template accessors
		//$this->sourceItems();

		$response = $this->renderWith($this->template);
		FormResponse::update_dom_id($this->id(), $response, 1);
		FormResponse::set_non_ajax_content($response);
		return FormResponse::respond();
	}
	/**
	 * Add existing member to group rather than creating a new member
	 */
	function addtogroup() {
		$data = $_REQUEST;
		unset($data['ID']);
		$ctfID = isset($data['ctf']) ? $data['ctf']['ID'] : null;

		if(!is_numeric($ctfID)) {
			FormResponse::status_messsage(_t('MemberTableField.ADDINGFIELD', 'Adding failed'), 'bad');
		}

		$className = Object::getCustomClass($this->stat('data_class'));
		$record = new $className();

		$record->update($data);
		
		$valid = $record->validate();

		if($valid->valid()) {
			$record->write();
			$record->Groups()->add($ctfID);

			$this->sourceItems();

			// TODO add javascript to highlight added row (problem: might not show up due to sorting/filtering)
			FormResponse::update_dom_id($this->id(), $this->renderWith($this->template), true);
			FormResponse::status_message(_t('MemberTableField.ADDEDTOGROUP','Added member to group'), 'good');
		
		} else {
			FormResponse::status_message(Convert::raw2xml("I couldn't add that user to this group:\n\n" . $valid->starredlist()), 'bad');
		}

		return FormResponse::respond();
	}
 /**
  * Add existing member to group rather than creating a new member
  */
 function addtogroup()
 {
     // Protect against CSRF on destructive action
     $token = $this->getForm()->getSecurityToken();
     if (!$token->checkRequest($this->controller->getRequest())) {
         return $this->httpError(400);
     }
     $data = $_REQUEST;
     $groupID = isset($data['ctf']['ID']) ? $data['ctf']['ID'] : null;
     if (!is_numeric($groupID)) {
         FormResponse::status_messsage(_t('MemberTableField.ADDINGFIELD', 'Adding failed'), 'bad');
         return;
     }
     // Get existing record either by ID or unique identifier.
     $identifierField = Member::get_unique_identifier_field();
     $className = self::$data_class;
     $record = null;
     if (isset($data[$identifierField])) {
         $record = DataObject::get_one($className, sprintf('"%s" = \'%s\'', $identifierField, $data[$identifierField]));
         if ($record && !$record->canEdit()) {
             return $this->httpError('401');
         }
     }
     // Fall back to creating a new record
     if (!$record) {
         $record = new $className();
     }
     // Update an existing record, or populate a new one.
     // If values on an existing (autocompleted) record have been changed,
     // they will overwrite current data. We need to unset 'ID'
     // record as it points to the group rather than the member record, and would
     // cause the member to be written to a potentially existing record.
     unset($data['ID']);
     $record->update($data);
     // Validate record, mainly password restrictions.
     // Note: Doesn't use Member_Validator
     $valid = $record->validate();
     if ($valid->valid()) {
         $record->write();
         $record->Groups()->add($groupID);
         $this->sourceItems();
         // TODO add javascript to highlight added row (problem: might not show up due to sorting/filtering)
         FormResponse::update_dom_id($this->id(), $this->renderWith($this->template), true);
         FormResponse::status_message(_t('MemberTableField.ADDEDTOGROUP', 'Added member to group'), 'good');
     } else {
         $message = sprintf(_t('MemberTableField.ERRORADDINGUSER', 'There was an error adding the user to the group: %s'), Convert::raw2xml($valid->starredList()));
         FormResponse::status_message($message, 'bad');
     }
     return FormResponse::respond();
 }
Exemple #5
0
 /** 
  * Saves the Dataobjects contained in the field
  */
 function saveInto(DataObject $record)
 {
     // CMS sometimes tries to set the value to one.
     if (is_array($this->value)) {
         $newFields = array();
         // Sort into proper array
         $value = ArrayLib::invert($this->value);
         $dataObjects = $this->sortData($value, $record->ID);
         // New fields are nested in their own sub-array, and need to be sorted separately
         if (isset($dataObjects['new']) && $dataObjects['new']) {
             $newFields = $this->sortData($dataObjects['new'], $record->ID);
         }
         // Update existing fields
         // @todo Should this be in an else{} statement?
         $savedObjIds = $this->saveData($dataObjects, $this->editExisting);
         // Save newly added record
         if ($savedObjIds || $newFields) {
             $savedObjIds = $this->saveData($newFields, false);
         }
         // Add the new records to the DataList
         if ($savedObjIds) {
             foreach ($savedObjIds as $id => $status) {
                 $this->getDataList()->add($id);
             }
         }
         // Update the internal source items cache
         $this->value = null;
         $items = $this->sourceItems();
         FormResponse::update_dom_id($this->id(), $this->FieldHolder());
     }
 }
 /** 
  * Saves the Dataobjects contained in the field
  */
 function saveInto(DataObject $record)
 {
     // CMS sometimes tries to set the value to one.
     if (is_array($this->value)) {
         $newFields = array();
         // Sort into proper array
         $value = ArrayLib::invert($this->value);
         $dataObjects = $this->sortData($value, $record->ID);
         // New fields are nested in their own sub-array, and need to be sorted separately
         if (isset($dataObjects['new']) && $dataObjects['new']) {
             $newFields = $this->sortData($dataObjects['new'], $record->ID);
         }
         // Update existing fields
         // @todo Should this be in an else{} statement?
         $savedObjIds = $this->saveData($dataObjects, $this->editExisting);
         // Save newly added record
         if ($savedObjIds || $newFields) {
             $savedObjIds = $this->saveData($newFields, false);
         }
         // Optionally save the newly created records into a relationship
         // on $record. This assumes the name of this formfield instance
         // is set to a relationship name on $record.
         if ($this->relationAutoSetting) {
             $relationName = $this->Name();
             if ($record->has_many($relationName) || $record->many_many($relationName)) {
                 if ($savedObjIds) {
                     foreach ($savedObjIds as $id => $status) {
                         $record->{$relationName}()->add($id);
                     }
                 }
             }
         }
         // Update the internal source items cache
         $this->value = null;
         $items = $this->sourceItems();
         FormResponse::update_dom_id($this->id(), $this->FieldHolder());
     }
 }
 /**
  * Use the URL-Parameter "action_saveComplexTableField"
  * to provide a clue to the main controller if the main form has to be rendered,
  * even if there is no action relevant for the main controller (to provide the instance of ComplexTableField
  * which in turn saves the record.
  *
  * @see {Form::ReferencedField}).
  */
 function saveComplexTableField()
 {
     if (isset($_REQUEST['ctf']['childID']) && is_numeric($_REQUEST['ctf']['childID'])) {
         $childObject = DataObject::get_by_id($this->sourceClass, $_REQUEST['ctf']['childID']);
     } else {
         $childObject = new $this->sourceClass();
         $this->fields->removeByName('ID');
     }
     $this->saveInto($childObject);
     $funcName = $this->controller->itemWriteMethod;
     if (!$funcName) {
         $funcName = "write";
     }
     $childObject->{$funcName}();
     // if ajax-call in an iframe, update window
     if (Director::is_ajax()) {
         // Newly saved objects need their ID reflected in the reloaded form to avoid double saving
         $form = $this->controller->DetailForm($childObject->ID);
         $form->loadDataFrom($childObject);
         FormResponse::update_dom_id($form->FormName(), $form->formHtmlContent(), true, 'update');
         return FormResponse::respond();
     } else {
         Director::redirectBack();
     }
 }
	/** 
	 * Saves the Dataobjects contained in the field
	 */
	function saveInto(DataObject $record) {
		// CMS sometimes tries to set the value to one.
		if(is_array($this->value)){
			
			// Sort into proper array
			$this->value = ArrayLib::invert($this->value);
			$dataObjects = $this->sortData($this->value, $record->ID);
			if(isset($dataObjects['new']) && $dataObjects['new']) {
				$newFields = $this->sortData($dataObjects['new'], $record->ID);
			}

			$savedObj = $this->saveData($dataObjects, $this->editExisting);
			if($savedObj && isset($newFields)) {
				$savedObj = $this->saveData($newFields,false);
			} else if(isset($newFields)) {
				$savedObj = $this->saveData($newFields,false);
			}
			$items = $this->sourceItems();
			FormResponse::update_dom_id($this->id(), $this->FieldHolder());
		}
	}