Beispiel #1
0
	def theme_checkbox(self, form_id, element):
		attribs = element.attr('attributes', {})
		attribs['name'] = element.get_element_name()
		attribs['value'] = element.attr('value', 1)
		if(element.attr('checked', False)):
			attribs['checked'] = None
		if(element.attr('disabled', False)):
			attribs['disabled'] = None
		return tags.label()[[
			tags.input(type='checkbox', **attribs),
			element.attr('text', '')
		]]
Beispiel #2
0
	def theme_radiogroup(self, form_id, element):
		comparator = element.attr('sort', cmp)
		options_clone = copy.copy(element.attr('options', []))
		option_keys, option_data = self._mangle_option_data(options_clone, comparator)
		
		def _create_radio(value, default_value):
			attribs = {}
			if(str(value) == str(default_value)):
				attribs['checked'] = None
			attribs['value'] = value
			attribs['type'] = 'radio'
			attribs['name'] = element.get_element_name()
			return tags.input(**attribs)
		
		element = [str(tags.label()[[
			_create_radio(key, element.attr('value', None)),
			' ', option_data[key]
		]]) for key in option_keys]
		
		return tags.div(_class="radio-group")[''.join(element)]
Beispiel #3
0
	def theme_element(self, form_id, element, rendered_element):
		content = ''
		
		if not(element.attr('basic_element', False)):
			if(element.attr('required', False)):
				asterisk = tags.span(_class="required")['*']
			else:
				asterisk = ''
			
			if(hasattr(element, 'label')):
				content += tags.label(_class="field-label")[[element.label, asterisk]]
			
		prefix = element.attr('prefix', False)
		if(callable(prefix)):
			content += prefix(element)
		elif(prefix):
			content += str(prefix)
		
		content += rendered_element
			
		suffix = element.attr('suffix', False)
		if(callable(suffix)):
			content += suffix(element)
		elif(suffix):
			content += str(suffix)
		
		if not(element.attr('basic_element', False)):
			if(hasattr(element, 'help')):
				content += tags.div(_class='form-help')[element.help]
			
			if(element.has_errors(recurse=False)):
				element_class = 'form-item form-error'
			else:
				element_class = 'form-item'
			
			item_id = 'form-item-%s' % element.name
			if(element.attr('deep_form_ids', False, recurse=True)):
				item_id = 'form-item-%s' % '-'.join(element.get_element_path())
			content = tags.div(_class=element_class, _id=item_id)[content]
		
		return content
Beispiel #4
0
	def get_element(self, req, style, storable):
		"""
		@see: L{modu.editable.define.definition.get_element()}
		"""
		frm = form.FormNode(self.name)
		if(style == 'search'):
			frm(type='textfield', size=10) 
		else:
			assets.activate_jquery(req)
			
			value = getattr(storable, self.get_column_name(), '')
			if not(value):
				value = '(none)'
			
			if(style == 'listing'):
				frm(
					type		= 'label',
					value		= value,
				)
			else:
				prefix = tags.label(id="%s-label" % self.name)[value]
				
				frm(
					type		= 'hidden',
					value		= value,
					attributes	= dict(
									id	= "%s-field" % self.name
					),
					prefix		= prefix,
					suffix		= tags.script(type="text/javascript")["""
									$('#%s-label').html($('#%s-field').val());
								""" % (self.name, self.name)
					]
				)
		
		return frm