ENHANCEMENT Improved customTag support

This commit is contained in:
chillu 2008-09-30 18:12:17 +00:00
parent e75e5a5a45
commit 5f46497799
6 changed files with 63 additions and 26 deletions

24
LICENSE
View File

@ -0,0 +1,24 @@
* Copyright (c) 2008, Silverstripe Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Silverstripe Ltd. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Silverstripe Ltd. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

8
README
View File

@ -10,10 +10,4 @@ Ingo Schommer (Nickname: ischommer)
SilverStripe 2.3
# Documentation
http://doc.silverstripe.com/doku.php?id=modules:tagfield
# Installation Instructions
CAUTION: Work in progress, the module trunk is most likely not useable
# Usage Overview
...
http://doc.silverstripe.com/doku.php?id=modules:tagfield

View File

@ -48,7 +48,7 @@ class TagField extends TextField {
/**
* @var array $customTags Override the tagging behaviour with a custom set
* used by {@link suggest()}.
* which is used by the javascript library directly instead of querying {@link suggest()}.
*/
protected $customTags;
@ -62,11 +62,21 @@ class TagField extends TextField {
Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery.js");
Requirements::javascript("tagfield/javascript/jquery.tags.js");
Requirements::css("tagfield/css/TagField.css");
Requirements::customScript("jQuery(document).ready(function() {
$('#" . $this->id() . "').tagSuggest({
url: '" . $this->Link() . "/suggest'
});
});");
if($this->customTags) {
Requirements::customScript("jQuery(document).ready(function() {
$('#" . $this->id() . "').tagSuggest({
tags: " . Convert::raw2json($this->customTags) . "
});
});");
} else {
Requirements::customScript("jQuery(document).ready(function() {
$('#" . $this->id() . "').tagSuggest({
url: '" . $this->Link() . "/suggest',
separator: '" . $this->separator . "'
});
});");
}
return parent::Field();
}
@ -79,7 +89,7 @@ class TagField extends TextField {
public function suggest($request) {
$tagTopicClassObj = singleton($this->tagTopicClass);
$searchString = $request->requestVar($this->Name());
$searchString = $request->requestVar('tag');
if($this->customTags) {
$tags = $this->customTags;
@ -152,7 +162,7 @@ class TagField extends TextField {
}
protected function combineTagsFromArray($tagsArr) {
return implode($this->separator, $tagsArr);
return ($tagsArr) ? implode($this->separator, $tagsArr) : array();
}
/**
@ -237,5 +247,13 @@ class TagField extends TextField {
return $this->separator;
}
public function setCustomTags($tags) {
$this->customTags = $tags;
}
public function getCustomTags() {
return $this->customTags;
}
}
?>

View File

@ -1,11 +1,12 @@
.field.tag span.tagMatches {
margin-left: 10px;
display: block;
margin-top: 5px;
}
.field.tag span.tagMatches span {
padding: 2px;
margin-right: 4px;
background-color: #0000AB;
background-color: #4EA3D7;
color: #fff;
cursor: pointer;
}

View File

@ -264,4 +264,4 @@
setSelection();
});
};
})(jQuery);
})(jQuery);

View File

@ -64,7 +64,7 @@ class TagFieldTest extends FunctionalTest {
'get',
'TagFieldTestController/ObjectTestForm/fields/Tags/suggest',
null,
array('Tags' => 'tag')
array('tag' => 'tag')
);
$this->assertEquals($field->suggest($request), '["tag1","tag2"]');
@ -73,7 +73,7 @@ class TagFieldTest extends FunctionalTest {
'get',
'TagFieldTestController/ObjectTestForm/fields/Tags/suggest',
null,
array('Tags' => 'tag1')
array('tag' => 'tag1')
);
$this->assertEquals($field->suggest($request), '["tag1"]');
@ -83,7 +83,7 @@ class TagFieldTest extends FunctionalTest {
'get',
'TagFieldTestController/ObjectTestForm/fields/Tags/suggest',
null,
array('Tags' => 'TAG1')
array('tag' => 'TAG1')
);
$this->assertEquals($field->suggest($request), '["tag1"]');
@ -92,7 +92,7 @@ class TagFieldTest extends FunctionalTest {
'get',
'TagFieldTestController/ObjectTestForm/fields/Tags/suggest',
null,
array('Tags' => 'unknown')
array('tag' => 'unknown')
);
$this->assertEquals($field->suggest($request), '[]');
}
@ -105,7 +105,7 @@ class TagFieldTest extends FunctionalTest {
'get',
'TagFieldTestController/TextbasedTestForm/fields/Tags/suggest',
null,
array('TextbasedTags' => 'tag')
array('tag' => 'tag')
);
$this->assertEquals($field->suggest($request), '["textbasedtag1","textbasedtag2"]');
@ -114,7 +114,7 @@ class TagFieldTest extends FunctionalTest {
'get',
'TagFieldTestController/TextbasedTestForm/fields/Tags/suggest',
null,
array('TextbasedTags' => 'tag1')
array('tag' => 'tag1')
);
$this->assertEquals($field->suggest($request), '["textbasedtag1"]');
@ -123,7 +123,7 @@ class TagFieldTest extends FunctionalTest {
'get',
'TagFieldTestController/TextbasedTestForm/fields/Tags/suggest',
null,
array('TextbasedTags' => 'TAG1')
array('tag' => 'TAG1')
);
$this->assertEquals($field->suggest($request), '["textbasedtag1"]');
@ -132,7 +132,7 @@ class TagFieldTest extends FunctionalTest {
'get',
'TagFieldTestController/TextbasedTestForm/fields/Tags/suggest',
null,
array('TextbasedTags' => 'unknown')
array('tag' => 'unknown')
);
$this->assertEquals($field->suggest($request), '[]');
}