def create_hidden_point_div(self): hidden_point_div = HTMLgen.Div(**{'class':'hiddenformdata'}) new_points = self.confirmupdate.new_points for point_index in xrange(0,9): point_position = point_index+1 point_name_value = "" point_node_value = "" if len(new_points) > point_index: point_cfg = new_points[point_position-1] point_name_value = point_cfg['name'] point_node_value = point_cfg['node'] point_name_id = "point%d" % point_position name_input = CustomInput(**{ 'type':'hidden', 'value':point_name_value, 'name':point_name_id, 'id':point_name_id, }) hidden_point_div.append(name_input) point_node_id = "node%d" % point_position node_input = CustomInput(**{ 'type':'hidden', 'value':point_node_value, 'name':point_node_id, 'id':point_node_id, }) hidden_point_div.append(node_input) hidden_point_div.append(CustomInput( **{"type":"hidden","id":"period", "name":"period", "value":self.confirmupdate.new_period})) return hidden_point_div
def __init__(self, *contents, **kw): span_kw = kw.copy() self.from_id = span_kw["from.id"] del span_kw["from.id"] self.to_id = span_kw["to.id"] del span_kw["to.id"] self.from_value = span_kw["from.value"] del span_kw["from.value"] self.to_value = span_kw["to.value"] del span_kw["to.value"] from_kw = { "id": self.from_id, "name": self.from_id, "value": self.from_value } to_kw = {"id": self.to_id, "name": self.to_id, "value": self.to_value} self.from_input = CustomInput(**from_kw) self.to_input = CustomInput(**to_kw) new_contents = [ CustomLabel("From:"), self.from_input, CustomLabel("To:"), self.to_input ] new_contents.extend(contents) HTMLgen.Span.__init__(self, *new_contents, **span_kw) return
def create_confirm_form(self): confirm_form = CustomForm('/trendmanager') confirm_form.submit = HTMLgen.Span(**{"class":"savespan"}) confirm_form.submit.append( CustomInput(type='hidden', name='trend', value=self.confirmupdate.encoded_name) ) confirm_form.submit.append( CustomInput(type='submit', name='confirmupdate', value='Commit') ) confirm_form.submit.append( CustomInput(type='submit', name='cancelupdate', value='Cancel') ) return confirm_form
def create_point_confirmation(self): point_confirmation_div = HTMLgen.Div(**{'class':'confirmationdiv'}) delete_control = HTMLgen.Select((("Delete existing data","1"), ("Save existing data","0")), **{"name":"deletedata", "size":1, "selected":("1",),}) confirmation_text = HTMLgen.Text( "Warning: Changing the name or value of a previously" " defined trend point my lead to unexpected results" " with existing data. It is highly recommended that" " you delete the existing trend data: " ) if self.confirmupdate.delete_level > 1: confirmation_text = HTMLgen.Text( "Warning: Adding points to an existing trend requires" " deleting existing trend data. Confirming changes" " will delete the existing trend data." ) delete_control = CustomInput(**{ 'type':'hidden', 'value':"1", 'name':'deletedata', }) point_confirmation_div.append( confirmation_text, delete_control ) return point_confirmation_div
def __init__(self, *contents, **kw): span_kw = kw.copy() self.input_id = span_kw["input.id"] del span_kw["input.id"] self.button_id = "%sbutton" % self.input_id input_kw = { "id": self.input_id, "name": self.input_id, "onChange": self.change_button_color(), "class": "color", } if span_kw.has_key("input.value"): input_kw["value"] = self.color_attr(span_kw["input.value"]) del span_kw["input.value"] button_kw = { "type": "button", "id": self.button_id, "name": self.button_id, "class": "color", "onclick": self.open_color_selector() } if input_kw.has_key("value"): button_kw["style"] = "background-color: %s" % input_kw["value"] self.input = CustomInput(**input_kw) self.button = CustomButton(**button_kw) new_contents = [self.input, self.button] new_contents.extend(contents) HTMLgen.Span.__init__(self, *new_contents, **span_kw) return
def create_document_structure(self): self.document = HTMLgen.SimpleDocument( title='trendMANAGER', stylesheet='/omega/trendmanager/styles.css', script=[ HTMLgen.Script(src="/webapi/js/ColorPicker2.js"), HTMLgen.Script(code=""" window.ColorPicker_targetButton = null; function pickColor(color) { ColorPicker_targetInput.value = color; ColorPicker_targetButton.style.backgroundColor = color; return; } var cp = new ColorPicker('window'); function open_color_selector(input_id, button_id) { var input = document.getElementById(input_id); var button = document.getElementById(button_id); window.ColorPicker_targetButton = button; cp.select(input, input_id); return; } function change_button_color(input_id, button_id) { var input = document.getElementById(input_id); var button = document.getElementById(button_id); var color = input.value; button.style.backgroundColor = color; return; } """) ]) # Hack-around to set the class on the BODY for HTMLGen self.document.append( HTMLgen.Script(code=""" document.body.className = 'manager'; """)) page_heading = HTMLgen.Heading(2, "Trend Preferences", id="editorlabel") self.document.append(page_heading) section = HTMLgen.Div(**{'class': 'section'}) form = CustomForm('/trendmanager') # # Also, create methods in request handler to extract the values # to make changing the form easier. # self.generalpreferencescontainer = HTMLgen.Div( **{'id': 'generalpreferencescontainer'}) form.append(self.generalpreferencescontainer) self.pointpreferencescontainer = HTMLgen.Div( **{'id': 'pointpreferencescontainer'}) form.append(self.pointpreferencescontainer) self.axespreferencescontainer = HTMLgen.Div( **{'id': 'axespreferencescontainer'}) form.append(self.axespreferencescontainer) form.submit = HTMLgen.Span(**{"class": "savespan"}) form.submit.append( CustomInput(type='hidden', name='trend', value=self.encoded_name)) form.submit.append( CustomInput(type='submit', name='commitpreferences', value='Commit')) form.submit.append( CustomInput(type='submit', name='cancelpreferences', value='Cancel')) form.submit.append( CustomInput(type='submit', name='reloadpreferences', value='Reload')) section.append(form) self.document.append(section) return
def add_general_preferences(self): container = self.generalpreferencescontainer table = HTMLgen.TableLite(**{"width": "100%"}) table.append(HTMLgen.TR(HTMLgen.TH("General Preferences"))) preferences = self.trend_configuration['preferences'] display_name_value = preferences['title'] width_value = preferences['width'] height_value = preferences['height'] backgroundcolor_value = preferences['background']['color'] textcolor_value = preferences['text']['color'] textsize_value = preferences['text']['fontsize'] textfont_value = preferences['text']['fontname'] timespanvalue_value = preferences['timespan']['value'] timespanunit_value = preferences['timespan']['unit'] timereference_value = preferences['time-reference'] frameset = HTMLgen.Frameset( HTMLgen.Span( CustomLabel("Display Name:", **{"for": "displayname"}), CustomInput( **{ "id": "displayname", "name": "displayname", "value": display_name_value }), **{"style": "white-space: nowrap"}), HTMLgen.Span( CustomLabel("Width:", **{"for": "width"}), CustomInput( **{ "id": "width", "name": "width", "class": "i4d", "value": width_value }), CustomLabel("Height:", **{"for": "height"}), CustomInput( **{ "id": "height", "name": "height", "class": "i4d", "value": height_value }), **{"style": "white-space: nowrap"}), HTMLgen.Span( CustomLabel("Background Color:", **{"for": "backgroundcolor"}), ColorSpan( **{ "input.id": "backgroundcolor", "input.value": backgroundcolor_value }), **{"style": "white-space: nowrap"}), HTMLgen.Span( CustomLabel("Text Color:", **{"for": "textcolor"}), ColorSpan(**{ "input.id": "textcolor", "input.value": textcolor_value }), CustomLabel("Text Size:", **{"for": "textsize"}), CustomInput( **{ "id": "textsize", "name": "textsize", "class": "i2d", "value": textsize_value }), CustomLabel("Font:", **{"for": "textfont"}), CustomInput(**{ "id": "textfont", "name": "textfont", "value": textfont_value }), **{"style": "white-space: nowrap"}), HTMLgen.Span( CustomLabel("Initial Timespan:", **{"for": "timespanvalue"}), CustomInput( **{ "id": "timespanvalue", "name": "timespanvalue", "class": "i4d", "value": timespanvalue_value }), HTMLgen.Select( (("samples", "samples"), ("hours", "hours"), ("minutes", "minutes"), ("seconds", "seconds")), **{ "name": "timespanunit", "size": 1, "selected": (timespanunit_value, ) }), **{"style": "white-space: nowrap"}), HTMLgen.Span( CustomLabel("Time Reference:", **{"for": "timereference"}), HTMLgen.Select( (("Mediator", "Mediator"), ("UTC", "UTC"), ("Browser", "Browser")), **{ "name": "timereference", "size": 1, "selected": (timereference_value, ) }), **{"style": "white-space: nowrap"}), ) table.append(HTMLgen.TR(HTMLgen.TD(frameset))) table.append( CustomInput(type='hidden', name='commitpreferences', value='Commit')) container.append(table) return
def render(self): # @todo Restructure like preferences, point_form -> form... self.trend_configuration = self.trend.configuration() document = HTMLgen.SimpleDocument( title='trendMANAGER', stylesheet='/omega/trendmanager/styles.css', script=[ HTMLgen.Script(code=nodeselectscript), HTMLgen.Script(code=updatenamescript), ]) # Hack-around to set the class on the BODY for HTMLGen document.append( HTMLgen.Script(code=""" document.body.className = 'manager'; """)) page_heading = HTMLgen.Heading(2, "Trend Point Configuration", id="editorlabel") document.append(page_heading) section = HTMLgen.Div(**{'class': 'section'}) point_form = CustomForm('/trendmanager') self.globalsettingscontainer = HTMLgen.Div( **{'id': 'globalsettingscontainer'}) point_form.append(self.globalsettingscontainer) self.add_global_settings() point_section = HTMLgen.Div(**{'class': 'section'}) point_table = HTMLgen.TableLite(**{'class': 'nodeEditTable'}) point_header = HTMLgen.TR(**{'class': 'trend_table_headers'}) for header in ['Point Name', 'Node Path']: header_id = "%sheader" % header.replace(' ', '').lower() headcell = HTMLgen.TH(header, scope="col", abbr=header, id=header_id) point_header.append(headcell) point_table.append(point_header) rowclasses = ['light', 'dark'] cd_points = self.trend_configuration['points'] for point_position in xrange(1, 10): point_row = HTMLgen.TR(**{'class': rowclasses[point_position % 2]}) point_name_value = "" point_node_value = "" if len(cd_points) >= point_position: point_cfg = cd_points[point_position - 1] point_name_value = point_cfg['name'] point_node_value = point_cfg['node'] point_name_id = "point%d" % point_position name_input = DojoInput( **{ 'value': point_name_value, 'name': point_name_id, 'id': point_name_id, }) name_column = HTMLgen.TD(**{"nowrap": True}) name_column.append(name_input) point_row.append(name_column) point_node_id = "node%d" % point_position node_input = DojoInput( **{ 'value': point_node_value, 'name': point_node_id, 'id': point_node_id, }) # @fixme Cool idea, need to swap order of node and name and # adding +/- capability would be extremely helpful in # user experience. #node_input.onChange = "update_point_name('%s','%s');" % ( # point_node_id, # point_name_id # ) node_column = HTMLgen.TD(**{ "class": "configuration", "nowrap": True }) node_column.append(node_input) browse_node_id = "browse%d" % point_position node_browse = CustomInput(**{ 'type': 'button', 'name': browse_node_id, 'value': '...', }) node_browse.onClick = "open_node_selector('%s');" % point_node_id button_column = HTMLgen.TD(**{"nowrap": True}) button_column.append(node_browse) point_row.append(node_column) point_row.append(button_column) point_table.append(point_row) point_table.append( CustomInput(type='hidden', name='commitpoints', value='Commit')) point_form.append(point_table) point_form.submit = HTMLgen.Span(**{"class": "savespan"}) point_form.submit.append( CustomInput(type='hidden', name='trend', value=self.encoded_name)) point_form.submit.append( CustomInput(type='submit', name='commitpoints', value='Commit')) point_form.submit.append( CustomInput(type='submit', name='cancelpoints', value='Cancel')) point_form.submit.append( CustomInput(type='submit', name='reloadpoints', value='Reload')) section.append(point_form) document.append(section) return str(document)
def __render_trend_row(self, request_path, display_name, trend_map, count): trend = trend_map[display_name] if trend is None: return None rowclasses = ['light', 'dark'] row = HTMLgen.TR(**{'class': rowclasses[count % 2]}) span = HTMLgen.Span(display_name, **{'style': 'white-space: pre;'}) row.append(HTMLgen.TH(span)) try: if not trend.get_points(): domish(row).setAttribute('class', 'nopoints') actioncell = HTMLgen.TD(**{"nowrap": True}) last_action = actioncell encoded_name = urllib.quote_plus(trend.name) # @note Using display text as URL is a bad idea... # @note More of a combo box approach would be better. # @note I don't think all the forms and hidden inputs are needed. # either use a single form and the input name, or use # multiple forms with encoded request paths... Or? actions = [ 'view trend', 'configure points', 'trend preferences', ' - ' ] for action in actions: form_id = action.lstrip().rstrip() + cgi.escape(trend.name) if action == 'view trend': actionform = CustomForm(request_path) actionname = 'reload' elif action == 'trend preferences': actionform = CustomForm(request_path, targetType='ignore') if (trend.klass == 'log') and (len(trend.get_points()) > 9): actionform.submit.onClick = ( "(alert('This trend is configured via /services/logger and has more than 9 points. Viewing/configuring points for this trend is currently not supported.'));return false;" ) else: actionform.submit.id = ("%sbutton") % encoded_name actionform.submit.onClick = ( "getTrendPreferences('%s', '%s');" % (encoded_name, actionform.submit.id)) elif action == ' - ': actionform = CustomForm(request_path, targetID='trend-config-table', id=form_id) actionname = action.replace(' ', '').lower() else: actionform = CustomForm(request_path, targetType='dialog') actionname = action.replace(' ', '').lower() actionform.name = action.title() actioninput = CustomInput(name=actionname, value=encoded_name, type='hidden') if trend.klass == 'log': if action in ['configure points', '-']: actionform.submit.disabled = True actioninput.disabled = True else: if action == ' - ': actionform.name = 'Remove Trend' actionform.submit.onClick = ( "return (confirmDialog('" + form_id + "', 'Delete trend <b>%s</b> and its" " configuration?', false));" % trend.name) actionform.klass = 'manual' if action == 'view trend': if (trend.klass == 'log') and (len(trend.get_points()) > 9): actionform.submit.onClick = ( "(alert('This trend is configured via /services/logger and has more than 9 points. Viewing/configuring points for this trend is currently not supported.'));return false;" ) else: actionform.klass = 'manual' preferences = trend.get_preferences() window_width = preferences['width'] window_height = preferences['height'] window_title = preferences['title'] #actionform.cgi=None actionform.submit.onClick = ( "openWindow('%s?viewtrend=%s','%s'); return false;" % (request_path, encoded_name, trend.name.replace(' ', '_').replace('.', '_'))) if not trend.get_points(): # No point in viewing graph with no points. actionform.submit.disabled = True #actioninput.disabled=True actionform.append(actioninput) actionform.submit.value = action externally_managed = getattr(trend, 'externally_managed', False) if externally_managed and action != 'view trend': actionform.submit.disabled = True actioncell.append(actionform) # Add row row.append(actioncell) except Exception, e: cell = HTMLgen.TD( "Invalid configuration: Please validate the configuration using ConfigTool." ) rowid = 'row%s' % count dots = "[+]" js = "var element = document.getElementById('%s'); if(element.innerHTML == '%s'){element.innerHTML='[-]<BR>%s'}else{element.innerHTML='%s'}" % ( rowid, dots, str(e).replace('\"', '').replace("\'", ""), dots) invalid_label = CustomLabel( id=rowid, onclick=js, style='color:red;text-decoration:underline;cursor: pointer') invalid_label.append(dots) cell.append(invalid_label) row.append(cell) msglog.exception() msg = ("Failed create row for: %s" % display_name) msglog.log('trendmanager', msglog.types.ERR, msg)