#-- # Copyright (c) 2012+ Damjan Rems # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #++ module DrgcmsFormFields ########################################################################### # Implementation of tree_select DRG CMS form field. Field will provides # multiple select functionality displayed as a tree. Might be used for selecting # multiple categories in a parent-child tree view.# # # ===Form options: # * +name:+ field name (required) # * +type:+ tree_select (required) # * +choices:+ Values for choices separated by comma. Values can also be specified like description:value. # In this case description will be shown to user, but value will be saved to document. # choices: 'OK:0,Ready:1,Error:2' # choices: Ruby,Pyton,PHP # * +eval:+ Choices will be provided by evaluating expression # eval: ModelName.choices4_field; Model class should define method which will provide data for field. # Data returned must be of type Array and have 3 elements. # 1 - description text # 2 - id value # 3 - parent id # * +html:+ html options which apply to select and text_field fields (optional) # # Form example: # 10: # name: categories # type: tree_select # eval: 'Categories.all_categories' # html: # size: 50x10 ########################################################################### class TreeSelect < Select ########################################################################### # Prepare choices for tree data rendering. ########################################################################### def make_tree(parent) return '' unless @choices[parent.to_s] @html << '