APICHANGE: delete GenericDataAdmin, RelatedDataEditor, DropdownField_WithAdd and their related code (js, css, etc) from cms, sapphire, "GenericDataAdmin" name space has also been deleted from lang files. They are all added in the new module "genericdataadmin"

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@64528 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Normann Lou 2008-10-20 00:20:00 +00:00
parent a6e6a4387d
commit 249c7a7d12
7 changed files with 0 additions and 624 deletions

View File

@ -1,34 +0,0 @@
.RelatedDataEditor div.children_holder{
border: 2px solid rgb(134, 159, 206);
padding: 8px 0;
}
.RelatedDataEditor div.field{
margin-bottom: 0;
padding: 0 10px;
}
.RelatedDataEditor div.keyholder{
background: url(../../sapphire/images/relatedDatafield-key-grad.gif) bottom left repeat-x ;
}
.RelatedDataEditor div.keyholder label{
width: 140px;
margin-left: 0;
}
.RelatedDataEditor div.keyholder label span{
font-weight: bold;
float: right;
margin-right: 12px;
margin-top: 2px;
}
.relatedDataKey {
display: inline;
}
.nested div.keyholder{
background-image: url(../../sapphire/images/relatedDatafield-key-grad2.gif);
}
.nested div.children_holder{
border: 2px solid rgb(158, 220, 143);
padding: 8px 0;
}
.RelatedDataEditor .clear{
clear: both;
}

View File

@ -173,70 +173,4 @@ class DropdownField extends FormField {
return $ret;
}
}
/**
* Dropdown field with an add button to the right.
* The class is originally designed to be used by RelatedDataEditor
* However, it can potentially be used as a normal dropdown field with add links in a normal form
* @package forms
* @subpackage fields-basic
*/
class DropdownField_WithAdd extends DropdownField {
protected $addText, $useExistingText, $addLink, $useExistingLink;
public $editLink;
function __construct($name, $title = "", $source = array(), $addLink=null, $useExistingLink=null, $addText="Add", $useExistingText="Use Existing", $value = "", $form = null){
parent::__construct($name, $title, $source, $value, $form);
$this->addText = $addText;
$this->useExistingText = $useExistingText;
$this->addLink = $addLink;
$this->useExistingLink = $useExistingLink;
}
function emptyString($string){
}
/**
* Returns a <select> tag containing all the appropriate <option> tags and with add/useExisting link
*/
function Field() {
//Add these js file so that the DropdownField_WithAdd can work alone (in a webpage, rather than CMS).
Requirements::javascript(THIRDPARTY_DIR . '/prototype.js');
Requirements::javascript(THIRDPARTY_DIR . '/behaviour.js');
Requirements::javascript(THIRDPARTY_DIR . '/prototype_improvements.js');
Requirements::Javascript(SAPPHIRE_DIR . "/javascript/DropdownField_WithAdd.js");
$dropdown = parent::Field();
if($this->addLink) $addLink = <<<HTML
<a class="addlink link" id="{$this->name}_addLink" href="$this->addLink" style="display: inline; padding-left: 1em; text-decoration: underline;">$this->addText</a>
HTML;
if($this->useExistingLink) $useExistingLink = <<<HTML
<a class="useExistinglink link" id="{$this->name}_useExistingLink" href="$this->useExistingLink" style="display: none; padding-left: 1em; text-decoration: underline;">$this->useExistingText</a>
HTML;
if($this->editLink) $editLink = <<<HTML
<a class="editlink" id="{$this->name}_editLink" href="$this->editLink" style="display: inline; padding-left: 1em; text-decoration: underline;">edit</a>
HTML;
return $dropdown . $addLink . $useExistingLink . $editLink;
}
/**
* Add a class for this special label so that
* it can have special styling
*/
function Title() {
$title = parent::Title();
if( $title ) {
return <<<HTML
<span class="keylabel">$title</span>
HTML;
}
else
return '';
}
}
?>

View File

@ -1,155 +0,0 @@
<?php
/**
* RelatedDataEditor puts a "sub-form" into a form that lets you edit a record on the other side of a
* one-to-many relationship. For example, you could be editing a workshop, and you want to provide fields
* to edit the client contact for that workshop.
*
* RelatedDataEditor inserts a dropdown field and a number of developer-specified additional fields into the
* system
* @package forms
* @subpackage fields-relational
*/
class RelatedDataEditor extends FormField {
protected $children;
protected $dropdownField;
protected $isNested;
protected $showkeydropdown;
/**
* @param name The name of the relationship
* @param dropdown The values listed in the dropdown
* @param fields The fields to show
*/
function __construct($name, $dropdownField, $fields = null, $dropdownClass = 'relatedDataKey', $showKeyDropdown = true) {
Requirements::css(SAPPHIRE_DIR . "/css/RelatedDataEditor.css");
parent::__construct($name);
$this->dropdownField = $dropdownField;
$this->children = $fields;
$this->dropdownField->extraClass = $dropdownClass;
$this->showkeydropdown = $showKeyDropdown;
}
function transform(FormTransformation $trans){
$this->dropdownField->transform($trans);
if($this->children){
$children=array();
foreach($this->children as $child){
$child = $child->transform($trans);
$children[] = $child;
}
$this->children = $children;
}
return $this;
}
function IsNested(){
return $this->isNested;
}
function FieldHolder() {
$fieldName = $this->name . 'ID';
$relationName = $this->name;
Profiler::mark("RelatedDataEditor.FieldHolder", "get data");
$record = $this->form->getRecord();
$relatedObject = $record->$relationName();
Profiler::unmark("RelatedDataEditor.FieldHolder", "get data");
$this->dropdownField->Name = $this->name . '[ID]';
$this->dropdownField->Value = $record->$fieldName;
$extraclass = $this->IsNested()?"nested":"";
$result .= "<div id=\"$this->name\" class=\"$this->class groupfield $extraclass\" >";
$fieldholder = $this->dropdownField->FieldHolder();
if($this->showkeydropdown){
$result .= "<div id=\"{$this->name}_keyholder\" class=\"keyholder\">$fieldholder</div>";
if($this->children){
$result .= "<img id=\"{$this->name}_loading\" src=\"cms/images/network-save.gif\" style=\"display: none;\" />";
$result .= "<img id=\"{$this->name}_loaded\" src=\"cms/images/alert-good.gif\" style=\"display: none;\" />";
}
}else{
$result .= "<div id=\"{$this->name}_keyholder\" class=\"keyholder\" style=\"display: none\">$fieldholder</div>";
}
if($this->children){
$result .= "<div id= \"{$this->name}_childrenholder\" class=\"children_holder\">";
foreach($this->children as $child) {
if(!$child->isComposite()){
$childFieldName = $child->Name();
$child->Name = $this->name . '[' . $child->Name() . ']';
if($this->dropdownField->isSelected()) $child->Value = $relatedObject->$childFieldName;
$child->setForm($this->form);
$result .= $child->FieldHolder();
}else{
$fs = $child->FieldSet();
foreach($fs as $subfield){
$childFieldName = $subfield->Name();
$subfield->Name = $this->name . '[' . $subfield->Name() . ']';
if($this->dropdownField->isSelected()) $subfield->Value = $relatedObject->$childFieldName;
$subfield->setForm($this->form);
}
$result .= $child->FieldHolder();
}
}
$result .= "<div class=\"clear\">&nbsp;</div>";
$result .= "</div>";
}
$result .= "</div>";
return $result;
}
function saveInto($record) {
$fieldName = $this->name . 'ID';
$relationName = $this->name;
//If value[newID] exists, this is a newly added related data.
if($this->value['newID'])
$this->value['ID']=$this->value['newID'];
//if value['ID'] == 0, nothing needs to be saved
if($this->value['ID'] == 0){
$record->$fieldName = 0;
return;
}
// Set the relation ID and look up the related object from the database
$record->$fieldName = $this->value['ID'];
$relatedObject = $record->$relationName();
$this->compositeSaveInto($relatedObject);
$relatedID = $relatedObject->write();
if($relatedID != $this->value['ID']){
$record->$fieldName = $relatedID;
}
}
/**
* Smart, "form-like" saveInto, to allow for nested RelatedDataEditors
*/
function compositeSaveInto($dataObject) {
if($this->children) foreach($this->children as $child){
if($child->isComposite()){
$dataFields = $child->FieldSet()->dataFields();
foreach($dataFields as $field) {
$fieldVal = $this->value[$field->Name()];
$field->setValue($fieldVal);
if($field->Name() != "ID") $field->saveInto($dataObject);
}
}else{
$fieldVal = $this->value[$child->Name()];
$child->setValue($fieldVal);
if($child->Name() != "ID") $child->saveInto($dataObject);
}
}
}
}
?>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 B

View File

@ -1,110 +0,0 @@
DropdownField_WithAdd = Class.create();
DropdownField_WithAdd.applyTo('div.dropdownfield_withadd');
DropdownField_WithAdd.prototype = {
initialize: function() {
WithAdd_Link.applyToChildren(this, '.editlink');
WithAdd_Link.applyToChildren(this, '.link');
},
getAddLink: function(){
return this.getElementsByTagName('a')[0];
},
getUseExistingLink: function(){
return this.getElementsByTagName('a')[1];
},
toggleLinks: function(){
var addlink = this.getAddLink();
var useExistinglink = this.getUseExistingLink();
if(addlink.style.display == "none"){
addlink.style.display = "inline";
useExistinglink.style.display = "none";
}else{
addlink.style.display = "none";
useExistinglink.style.display = "inline";
}
}
}
WithAdd_Link = Class.create();
WithAdd_Link.prototype = {
onclick: function(){
this.toggleSiblingDropdown();
var ownerField = this.getOwnerField();
ownerField.toggleLinks();
var relatedDataEditor = this.getRelatedDataEditor();
if(relatedDataEditor){
if(this.className.match(/addlink/))
relatedDataEditor.status = 'adding';
else
relatedDataEditor.status = 'useexisting';
relatedDataEditor.linkOnClick();
}
return false;
},
findSiblingDropdown: function(){
return this.parentNode.getElementsByTagName('select')[0];
},
toggleSiblingDropdown: function(){
var dropdown = this.findSiblingDropdown();
if(dropdown.disabled)
dropdown.disabled = false;
else
dropdown.disabled = true;
},
getOwnerField: function(){
var f = this.parentNode;
while(f && !f.className.match(/dropdownfield_withadd/)) f=f.parentNode;
return f;
},
getRelatedDataEditor: function(){
var f = this.parentNode;
while(f && !f.className.match(/RelatedDataEditor/)) {
f=f.parentNode;
if(f.tagName.toLowerCase() == 'form') break;
}
return f;
}
}
WithAdd_Link = Class.create();
WithAdd_Link.prototype = {
initialize: function() {
this.checkDisplay();
},
onclick: function(){
var relatedDataEditor = this.getRelatedDataEditor();
if(relatedDataEditor){
relatedDataEditor.linkOnClick();
}
return false;
},
getRelatedDataEditor: function(){
var f = this.parentNode;
while(f && !f.className.match(/RelatedDataEditor/)) {
f=f.parentNode;
if(f.tagName.toLowerCase() == 'form') break;
}
return f;
},
checkDisplay: function(){
var dropdown = this.getdropdownField();
if(dropdown.value==0)
this.style.display = 'none';
else
this.style.display = 'inline';
},
getdropdownField: function(){
var f = this.parentNode;
var dropdown = f.getElementsByTagName('select')[0];
return dropdown;
}
}

View File

@ -1,259 +0,0 @@
RelatedDataEditor = Class.create();
RelatedDataEditor.applyTo('#Form_EditForm div.RelatedDataEditor');
RelatedDataEditor.prototype = {
initialize: function(){
var loading = $(this.id+"_loading");
if(loading){
loading.style.position = "absolute";
}
var loaded = $(this.id+"_loaded");
if(loaded){
loaded.style.position = "absolute";
}
var ownerForm = this.ownerForm()
ownerForm.observeMethod('BeforeSave', this.beforeSave.bind(this));
this.zeroToggle();
},
beforeSave: function(){
if(this.newKeyValue) {
var input = document.createElement('input');
input.name=this.id+"[newID]";
input.value=this.newKeyValue;
input.style.display = 'none';
this.appendChild(input);
}
},
reload: function(parentID){
var relatedClass = this.id
var url = getAjaxURL('updateRelatedKey', this.getOwnerID(), 'ajax=1&RelatedClass='+relatedClass+'&ParentID='+parentID);
var __relatedDataEditor = this;
new Ajax.Updater(
{success: $(this.id+'_keyholder')},
url,
{
method: 'get',
onFailure: function(response) {errorMessage("Error getting data", response);},
onComplete: function() {
Behaviour.apply(__relatedDataEditor);
var keyfield = __relatedDataEditor.findKeyField();
keyfield.onchange();
}
}
);
},
updatingEffect: function(){
var childrenHolder = this.findChildrenHolder();
var loading = $(this.id+"_loading");
if(loading){
loading.style.display = "block";
if(childrenHolder&&!childrenHolder.needToToggleAsBlock){
new Effect.Fade(childrenHolder, {to: .3, duration: 1});
}
}
},
loadedEffect: function(){
var childrenHolder = this.findChildrenHolder();
var loading = $(this.id+"_loading");
if(loading)
loading.style.display = "none";
var loaded = $(this.id+"_loaded");
if(loaded){
loaded.style.display = "block";
new Effect.Fade(loaded);
}
if(childrenHolder&&!childrenHolder.needToToggleAsBlock)
new Effect.Appear(childrenHolder);
},
findChildrenHolder: function(){
return $(this.id+'_childrenholder');
},
findKeyField: function(){
return this.getElementsByTagName('select')[0];
},
findChildren: function(entireForm){
if(entireForm){
var f = this.ownerForm();
var allInputs = f.getElementsByTagName('input');
var allTextareas = f.getElementsByTagName('textarea');
}else{
var allInputs = this.getElementsByTagName('input');
var allTextareas = this.getElementsByTagName('textarea');
}
var relatedFields = new Array();
var regEx = new RegExp('^'+this.id+'\\\[.+\\\]$');
for(var i=0; i<allInputs.length; i++){
if(allInputs[i].name.match(regEx)){
relatedFields.push(allInputs[i]);
}
}
for(var i=0; i<allTextareas.length; i++){
if(allTextareas[i].name.match(regEx)){
relatedFields.push(allTextareas[i]);
}
}
return relatedFields;
},
updateChildren: function(dataArray, entireForm){
var children = this.findChildren(entireForm);
for(var i=0; i<children.length; i++){
children[i].value = dataArray[children[i].name];
if(typeof(children[i].onchange)!='undefined'){
children[i].onchange();
}
}
},
getOwnerID: function(){
var ownerForm = this.ownerForm();
var fields = ownerForm.getElementsByTagName('input')
for(var i=0; i<fields.length; i++){
if(fields[i].name == 'ID') break;
}
return fields[i].value;
},
ownerForm: function() {
var f = this.parentNode;
while(f && f.tagName.toLowerCase() != 'form') f = f.parentNode;
return f;
},
setNewRelatedKey: function(id) {
this.newKeyValue = id;
},
unsetNewRelatedKey: function(){
this.newKeyValue = null;
},
linkOnClick: function(){
var relatedDataKey = this.findKeyField();
if(this.status == 'adding'){
relatedDataKey.onchange(false);
}else{
relatedDataKey.onchange();
}
var childrenHolder = this.findChildrenHolder();
if(childrenHolder) {
if(childrenHolder.needToToggleAsBlock){
if(childrenHolder.style.display == 'none')
childrenHolder.style.display = 'block';
else
childrenHolder.style.display = 'none';
}else{
var children = this.findChildren(false);
if(children) for(var i=0; i<children.length; i++){
if(children[i].needToToggle){
if(children[i].parentNode.parentNode.style.display == 'none'){
children[i].parentNode.parentNode.style.display = 'block';
} else {
children[i].parentNode.parentNode.style.display = 'none';
}
}
}
}
}
},
zeroToggle: function(){
var children = this.findChildren();
var key = this.findKeyField();
if(key.value == 0 && this.status != 'adding'){
for(var i=0; i<children.length; i++){
children[i].disabled = true;
}
} else {
for(var i=0; i<children.length; i++){
children[i].disabled = false;
}
}
}
}
Behaviour.register({
'select.relatedDataKey':{
onchange: function(withKey){
if(withKey == null) withKey = true;
var ownerField = this.getOwnerField();
ownerField.updatingEffect();
ownerField.zeroToggle();
var editlink = this.getEditLink();
if(editlink) editlink.checkDisplay();
var __relatedDataKey = this;
window.setTimeout(function() {
var owner = __relatedDataKey.getOwnerField();
var url = getAjaxURL("getRelatedData", owner.getOwnerID());
var id=__relatedDataKey.value;
var fieldSet = owner.findChildren(true);
if(withKey){
fieldSet[fieldSet.length] = __relatedDataKey;
}else{
for(var i=0; i<fieldSet.length; i++){
if(fieldSet[i].name == owner.id+"[ID]"){
fieldSet[i].value = null;
}
}
}
ajaxSubmitFieldSet(url, fieldSet, "RelatedClass="+owner.id);
owner.loadedEffect();
}, 1000);
},
getOwnerField: function(){
var f = this.parentNode;
while(f && !f.className.match(/RelatedDataEditor/)) f=f.parentNode;
return f;
},
getEditLink: function(){
var parent = this.parentNode;
var links = parent.getElementsByTagName('a');
for(var i=0; i<links.length; i++){
if(links[i].className == 'editlink') return links[i];
}
}
}
});
function getY(el){
var ret = 0;
while( el != null ) {
ret += el.offsetTop;
el = el.offsetParent;
}
return ret;
}
function getX(el){
var ret = 0;
while( el != null ) {
ret += el.offsetLeft;
el = el.offsetParent;
}
return ret;
}