[d34684]: / ForgeTracker / forgetracker / widgets / admin_custom_fields.py  Maximize  Restore  History

Download this file

146 lines (120 with data), 5.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import ew as ew_core
import ew.jinja2_ew as ew
from allura.lib.widgets import form_fields as ffw
from allura.lib.widgets import forms as f
class MilestonesAdmin(ffw.SortableTable):
defaults = dict(
ffw.SortableTable.defaults,
button=ffw.AdminField(field=ew.InputField(
css_class='add', field_type='button',
value='New Milestone')),
empty_msg='No milestones have been created.',
nonempty_msg='Drag and drop the milestones to reorder.',
repetitions=0)
fields = [
ew.HiddenField(name='old_name'),
ffw.Radio(name='default', label='Default',
css_class='default-milestone'),
ew.Checkbox(name='complete', show_label=True, suppress_label=True),
ew.TextField(name='name',
attrs={'style': 'width: 80px'}),
ffw.DateField(name='due_date',
attrs={'style': 'width: 80px'}),
ffw.AutoResizeTextarea(
name='description',
attrs={'style': 'height:1em; width: 150px'}),
ew.InputField(
label='Delete',
field_type='button',
attrs={'class': 'delete', 'value': 'Delete'}),
]
button = ew.InputField(
css_class='add', field_type='button', value='New Milestone')
def prepare_context(self, context):
response = super().prepare_context(context)
if 'value' in response:
for milestone_data in response['value']:
if 'name' in milestone_data:
milestone_data['old_name'] = milestone_data['name']
return response
def resources(self):
yield from super().resources()
yield ew.CSSScript('''div.state-field table{ width: 700px; }''')
class CustomFieldAdminDetail(ffw.StateField):
template = 'jinja:forgetracker:templates/tracker_widgets/custom_field_admin_detail.html'
defaults = dict(
ffw.StateField.defaults,
selector=ffw.AdminField(field=ew.SingleSelectField(
name='type',
options=[
ew.Option(py_value='string', label='Text'),
ew.Option(py_value='number', label='Number'),
ew.Option(py_value='boolean', label='Boolean'),
ew.Option(py_value='select', label='Select'),
ew.Option(py_value='milestone', label='Milestone'),
ew.Option(py_value='user', label='User'),
],
)),
states=dict(
select=ffw.FieldCluster(
fields=[
ffw.AdminField(field=ew.TextField(name='options',
label='Options (separate with spaces; quote if containing spaces; prefix with * to set a default)',
))],
show_labels=False),
milestone=ffw.FieldCluster(
# name='milestones',
fields=[MilestonesAdmin(name='milestones')])
))
class CustomFieldAdmin(ew.CompoundField):
template = 'jinja:forgetracker:templates/tracker_widgets/custom_field_admin.html'
def resources(self):
yield from super().resources()
yield ew.JSLink('tracker_js/custom-fields.js')
fields = [
ew.HiddenField(name='name'),
ew.TextField(name='label'),
ew.Checkbox(
name='show_in_search',
label='Show in list view',
show_label=True,
suppress_label=True),
CustomFieldAdminDetail()]
class TrackerFieldAdmin(f.ForgeForm):
submit_text = None
class fields(ew_core.NameList):
open_status_names = ew.TextField(label='Open Statuses')
closed_status_names = ew.TextField(label='Closed Statuses')
custom_fields = ffw.SortableRepeatedField(field=CustomFieldAdmin())
class buttons(ew_core.NameList):
save = ew.SubmitButton(label='Save')
def resources(self):
yield from self.fields['custom_fields'].resources()
class CustomFieldDisplay(ew.CompoundField):
template = 'jinja:forgetracker:templates/tracker_widgets/custom_field_display.html'
class CustomFieldsDisplay(ew.RepeatedField):
template = 'jinja:forgetracker:templates/tracker_widgets/custom_fields_display.html'
class TrackerFieldDisplay(f.ForgeForm):
class fields(ew_core.NameList):
milestone_names = ew.TextField()
open_status_names = ew.TextField(label='Open Statuses')
closed_status_names = ew.TextField(label='Open Statuses')
custom_fields = CustomFieldsDisplay()
def resources(self):
yield from self.fields['custom_fields'].resources()