-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput_wdg.py
More file actions
2571 lines (1939 loc) · 80.6 KB
/
Copy pathinput_wdg.py
File metadata and controls
2571 lines (1939 loc) · 80.6 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
###########################################################
#
# Copyright (c) 2005, Southpaw Technology
# All Rights Reserved
#
# PROPRIETARY INFORMATION. This software is proprietary to
# Southpaw Technology, and is not to be reproduced, transmitted,
# or disclosed in any way without written permission.
#
#
#
__all__ = [
'InputException', 'BaseInputWdg', 'TextWdg', 'FilterTextWdg', 'TextAreaWdg',
#'TextAreaWithSelectWdg',
'RadioWdg', 'CheckboxWdg', 'FilterCheckboxWdg', 'SelectWdg', 'FilterSelectWdg',
'MultiSelectWdg', 'ItemsNavigatorWdg', 'ButtonWdg',
'SubmitWdg', 'ActionSelectWdg', 'DownloadWdg',
'ResetWdg', 'PasswordWdg', 'HiddenWdg', 'NoneWdg', 'ThumbInputWdg',
'SimpleUploadWdg', 'UploadWdg', 'MultiUploadWdg',
'CalendarWdg', 'CalendarInputWdg',
"PopupWdg", "PopupMenuWdg"
]
import os, shutil, string, types
from pyasm.common import Common, Marshaller, Date, TacticException
from pyasm.biz import File, Snapshot, Pipeline, NamingUtil, ExpressionParser
from pyasm.web import *
from pyasm.search import Search, SearchKey, SearchException
from icon_wdg import IconButtonWdg, IconWdg
from operator import itemgetter
class InputException(Exception):
pass
class BaseInputWdg(HtmlElement):
ARGS_KEYS = {}
def get_args_keys(cls):
'''external settings which populate the widget'''
return cls.ARGS_KEYS
get_args_keys = classmethod(get_args_keys)
#def __init__(my,name=None, type=None, label=None):
def __init__(my, name=None, type=None, label=None, **kwargs):
super(BaseInputWdg,my).__init__(type)
# the name of the input element
my.name = name
my.input_prefix = None
my.value = ""
my.options = {}
my.options['default'] = ""
my.options['persist'] = "false"
my.persistence = False
my.persistence_obj = None
my.cached_values = None
my.label = label
my.disabled_look = True
my.prefix = ''
my.change_cbjs_action = ''
# deprecated
my.element = None
my.parent_wdg = None
my.state = {}
my.title = ''
my.related_type = None
# FIXME: need to make this more elegant: these are only put here
# to conform to the interface of BaseTableElementWdg so that these
# elements can be put into a TableWdg. This should be more formal
# because the relationship here is quite tenuous
def get_style(my):
return ""
def get_bottom(my):
return ""
def copy(my, input):
'''copies the parameters of one widget to the other. This is useful
for transfering the parameters specified in a config file to a contained
widget.'''
my.name = input.name
my.input_prefix = input.input_prefix
my.options = input.options
my.sobjects = input.sobjects
my.current_index = input.current_index
my.set_sobject = input.get_current_sobject()
def set_state(my, state):
'''Set the state for this table element'''
my.state = state
def get_state(my):
'''get the state for this table element'''
return my.state
def get_related_type(my):
'''Some input widgets will be related to a search type to define
a list or range of parameters. This will allow an external
widget to discover this relationship and provide a means to add
to this list'''
return my.related_type
def set_title(my, title):
my.title = title
def get_title(my):
'''Function that that gives a title represenation of this widget'''
if my.title:
return my.title
name = my.get_name()
title = string.replace(my.name, "_", " ")
title = title.capitalize()
span = SpanWdg(title)
required = my.get_option("required")
if required == "true":
my._add_required(span)
return span
def _add_required(my, span):
required_span = SpanWdg(" *")
required_span.add_style("color: #f44")
required_span.add_style("font-size: 1.0em")
span.add_tip("Required Field")
span.add(required_span)
def set_parent_wdg(my, parent_wdg):
'''method to set the parent widget. This is typicaly the EditWdg'''
my.parent_wdg = parent_wdg
def get_parent_wdg(my):
return my.parent_wdg
def set_layout_wdg(my, layout_wdg):
my.parent_wdg = layout_wdg
def get_prefs(my):
'''Function that that gives a preference widget for this input'''
return ""
def set_input_prefix(my, input_prefix):
my.input_prefix = input_prefix
def get_input_name(my, name=''):
input_name = my.name
if name:
input_name = name
if my.input_prefix:
return "%s|%s" % (my.input_prefix, input_name)
else:
return input_name
def set_name(my, name):
'''set the name externally'''
my.name = name
def get_name(my):
return my.name
def get_label(my):
if my.label:
return my.label
else:
return my.name
def set_options(my, options):
my.options = options
if my.has_option('search_key'):
search_key = options.get('search_key')
if search_key:
sobj = SearchKey.get_by_search_key(search_key)
my.set_sobjects([sobj])
def has_option(my, key):
return my.options.has_key(key)
def set_option(my, key, value):
my.options[key] = value
def get_option(my, key):
'''gets the value of the specified option'''
if my.options.has_key(key):
return my.options[key]
else:
return ""
def set_disabled_look(my, disable):
my.disabled_look = disable
def is_read_only(my):
''' if the read_only option is true, either set disabled or readonly'''
if my.get_option('read_only') in ['true', True]:
return True
return False
def is_edit_only(my):
return my.get_option('edit_only') == 'true'
def is_simple_viewable(my):
return True
def is_editable(my):
return True
def check_persistent_values(my, cgi_values):
web = WebContainer.get_web()
if my.is_form_submitted() and web.has_form_key(my.get_input_name()):
# if the form is submitted, then always use the submitted value
my._set_persistent_values(cgi_values)
my.cached_values = cgi_values
return cgi_values
else:
return False
def check_persistent_display(my, cgi_values):
# no longer checking for web.get_form_keys()
web = WebContainer.get_web()
if my.get_option("persist") == "true":
# old web implementation
if web.has_form_key(my.get_input_name()):
values = cgi_values
#my._set_persistent_values(values)
return values
else:
# try the json implementation if it has been set
from tactic.ui.filter import FilterData
filter_data = FilterData.get()
values = filter_data.get_values_by_prefix(my.prefix)
if values:
values = values[0]
value = values.get(my.get_input_name())
if value:
cgi_values = [value]
#my._set_persistent_values(cgi_values)
return cgi_values
return False
else:
return False
def get_values(my, for_display=False):
'''gets the current value of this input element. The order of
importance is as follows. If the form was submitted, this value
will always take precedence. Then externally set values through
code.'''
values = []
web = WebContainer.get_web()
# getting the value from CGI depends on whether this is for display
# of the widget or for getting the current value of this widget.
cgi_values = web.get_form_values( my.get_input_name() )
if for_display:
# get it from the sobject: this grabs the values from the
# sobject in the db for editing
column = my.get_option('column')
if not column:
column = my.name
if my.get_current_sobject() and \
my.get_current_sobject().has_value(column):
sobject = my.get_current_sobject()
values = [sobject.get_value(column)]
if not values:
values = []
return values
# if set explicitly, then this is the value
if my.value != '':
values = [my.value]
my._set_persistent_values(values)
return values
# the value is taken from CGI only if the input is persistent
values = my.check_persistent_display(cgi_values)
if values != False:
return values
else:
values = []
# This option will read the webstate if no explicit value is
# present
if my.get_option("web_state") == "true":
# this will eventually use the WebState: for now, use cgi
values = cgi_values
if values and values[0] != "":
my._set_persistent_values(values)
return values
# if this has been called before, get the previous value
elif my.cached_values != None:
return my.cached_values
# check for key existence only in for_display=False
#elif my.is_form_submitted() and web.has_form_key(my.get_input_name()):
# # if the form is submitted, then always use the submitted value
# my._set_persistent_values(cgi_values)
# my.cached_values = cgi_values
# return cgi_values
else:
temp_values = my.check_persistent_values(cgi_values)
if temp_values != False:
return temp_values
# if there are values in CGI, use these
if not for_display and cgi_values:
values = cgi_values
# if the value has been explicitly set, then use that one
elif my.value != '':
values = [my.value]
# otherwise, get it from the sobject: this grabs the values from the
# sobject in the db for editing
elif my.get_current_sobject() and \
my.get_current_sobject().has_value(my.name):
sobject = my.get_current_sobject()
values = [sobject.get_value(my.name)]
if not values:
values = []
# This option will read the webstate if no explicit value is
# present
elif my.get_option("web_state") == "true":
# this will eventually use the WebState: for now, use cgi
values = cgi_values
my._set_persistent_values(values)
my.cached_values = values
return values
# otherwise, get it from the persistence (database)
elif my.persistence:
class_path = Common.get_full_class_name(my.persistence_obj)
key = "%s|%s" % (class_path, my.name)
#values = WidgetSettings.get_key_values(key, auto_create=False)
values = WidgetSettings.get_key_values(key)
# if all of the above overrides fail, then set to the default
# the rules for persistent input is slightly different
if (values == None and my.persistence) or (values == [] and not my.persistence):
default = my.get_option("default")
if default != "":
# default can be a list
if isinstance(default, list):
values = default
else:
values = [default]
# evaluate an sobject expression
new_values = []
for value in values:
new_value = NamingUtil.eval_template(value)
new_values.append(new_value)
values = new_values
else:
values = []
if values:
#web.set_form_value(my.name, values[0])
web.set_form_value(my.get_input_name(), values)
my._set_persistent_values(values)
# only cache if it is not for display: otherwise we have to separate
# the for display cache and the non for display cache
if not for_display:
my.cached_values = values
return values
def _set_persistent_values(my, values):
if my.persistence:
class_path = Common.get_full_class_name(my.persistence_obj)
key = "%s|%s" % (class_path, my.name)
# make sure the value is not empty
if not values:
values = []
# if the current value is different from stored value, then update
# this check is done in set_key_values()
WidgetSettings.set_key_values(key, values)
def get_value(my, for_display=False):
values = my.get_values(for_display)
if not values:
return ""
else:
return values[0]
def set_value(my, value, set_form_value=True):
my.value = value
# some widgets do not have names (occasionally)
name = my.get_input_name()
if not name:
return
# when the value is explicitly set, the set then form value as such
if set_form_value:
web = WebContainer.get_web()
web.set_form_value(name, value)
def set_persistence(my, object=None):
my.persistence = True
if object == None:
object = my
my.persistence_obj = object
# this implies persist on submit (it is also faster)
my.set_persist_on_submit()
def set_persist_on_submit(my, prefix=''):
my.set_option("persist", "true")
my.prefix = prefix
def set_submit_onchange(my, set=True):
if set:
my.change_cbjs_action = 'spt.panel.refresh( bvr.src_el.getParent(".spt_panel") );'
#my.add_behavior(behavior)
else:
print("DEPRECATED: set_submit_onchange, arg set=False")
my.remove_event('onchange')
def is_form_submitted(my):
web = WebContainer.get_web()
if web.get_form_value("is_from_login") == "yes":
return False
# all ajax interactions are considered submitted as well
if web.get_form_value("ajax"):
return True
return web.get_form_value("is_form_submitted") == "yes"
def set_form_submitted(my, event='onchange'):
'''TODO: deprecated this: to declare if a form is submitted, used primarily for FilterCheckboxWdg'''
my.add_event(event, "document.form.elements['is_form_submitted'].value='yes'", idx=0)
def set_style(my, style):
'''Sets the style of the top widget contained in the input widget'''
my.element.set_style(style)
def get_key(my):
if not my.persistence_obj:
my.persistence_obj = my
key = "%s|%s"%(Common.get_full_class_name(my.persistence_obj), my.name)
return key
def get_save_script(my):
'''get the js script to save the value to widget settings for persistence'''
key = my.get_key()
return "spt.api.Utility.save_widget_setting('%s', bvr.src_el.value)" %key;
def get_refresh_script(my):
'''get a general refresh script. use this as a template if you need to pass in
bvr.src_el.value to values'''
return "var top=spt.get_parent_panel(bvr.src_el); spt.panel.refresh(top, {}, true)"
class BaseTextWdg(BaseInputWdg):
def handle_mode(my):
return
'''
# DISABLED for now
mode = my.options.get("mode")
if mode == "string":
behavior = {
'type': 'keyboard',
'kbd_handler_name': 'DgTableMultiLineTextEdit'
}
my.add_behavior(behavior)
elif mode in ["float", "integer"]:
behavior = {
'type': 'keyboard',
'kbd_handler_name': 'FloatTextEdit'
}
my.add_behavior(behavior)
'''
class TextWdg(BaseTextWdg):
ARGS_KEYS = {
'size': {
'description': 'width of the text field in pixels',
'type': 'TextWdg',
'order': 0,
'category': 'Options'
},
'read_only': {
'description': 'whether to set this text field to read-only',
'type': 'SelectWdg',
'values' : 'true|false',
'order': 1,
'category': 'Options'
}
}
def __init__(my,name=None, label=None):
super(TextWdg,my).__init__(name,"input", label=label)
my.css = "inputfield"
my.add_class(my.css)
my.add_class("spt_input")
my.add_color("background", "background", 10)
my.add_color("color", "color")
#my.add_style("width: 200px")
my.add_border()
def get_display(my):
my.set_attr("type", "text")
my.set_attr("name", my.get_input_name())
if my.is_read_only():
# do not set disabled attr to disabled cuz usually we want the data to
# get read and passed to callbacks
my.set_attr('readonly', 'readonly')
if my.disabled_look == True:
#my.add_class('disabled')
my.add_color("background", "background", -10)
value = my.get_value(for_display=True)
# this make sure that the display
if isinstance(value, basestring):
value = value.replace('"', '"')
my.set_attr("value", value)
size = my.get_option("size")
if size:
my.set_attr("size", size)
my.handle_mode()
return super(TextWdg,my).get_display()
class FilterTextWdg(TextWdg):
'''This composite text acts as a filter and can be, for instance,
used in prefs area in TableWdg'''
def __init__(my,name=None, label=None, css=None , is_number=False, has_persistence=True):
super(FilterTextWdg,my).__init__(name, label=label)
if is_number:
my.add_event('onchange',\
"val=document.form.elements['%s'].value; if (Common.validate_int(val))\
document.form.submit(); else \
{alert('[' + val + '] is not a valid integer.')}" %name)
else:
my.set_submit_onchange()
if has_persistence:
my.set_persistence()
else:
my.set_persist_on_submit()
my.css = css
my.unit = ''
def set_unit(my, unit):
my.unit = unit
def get_display(my):
my.handle_behavior()
if not my.label:
return super(FilterTextWdg, my).get_display()
else:
text = TextWdg.get_class_display(my)
span = SpanWdg(my.label, css=my.css)
span.add(text)
span.add(my.unit)
return span
def handle_behavior(my):
if my.persistence:
key = my.get_key()
value = WidgetSettings.get_value_by_key(key)
if value:
my.set_value(value)
behavior = {"type" : "change",
"cbjs_preaction":\
"spt.api.Utility.save_widget_setting('%s',bvr.src_el.value)"%key}
if my.change_cbjs_action:
behavior['cbjs_action'] = my.change_cbjs_action
my.add_behavior(behavior)
class TextAreaWdg(BaseTextWdg):
ARGS_KEYS = {
'rows': 'The number of rows to show',
'cols': 'The number of columns to show',
}
def __init__(my,name=None, **kwargs):
super(TextAreaWdg,my).__init__(name,"textarea")
# on OSX rows and cols flag are not respected
width = kwargs.get("width")
if width:
my.add_style("width", width)
height = kwargs.get("height")
if height:
my.add_style("height", height)
web = WebContainer.get_web()
browser = web.get_browser()
if browser == "Qt":
rows = None
cols = None
else:
rows = kwargs.get("rows")
cols = kwargs.get("cols")
if rows:
my.set_attr("rows", rows)
if cols:
my.set_attr("cols", cols)
browser = web.get_browser()
if not width and not cols:
width = 300
my.add_style("width", width)
my.add_class("spt_input")
my.add_border()
def get_display(my):
my.set_attr("name", my.get_input_name())
#my.add_style("font-family: Courier New")
my.add_color("background", "background", 10)
my.add_color("color", "color")
#my.add_border()
rows = my.get_option("rows")
cols = my.get_option("cols")
if not rows:
rows = 3
my.set_attr("rows", rows)
if not cols:
cols = 50
my.set_attr("cols", cols)
if my.is_read_only():
my.set_attr('readonly', 'readonly')
if my.disabled_look == True:
#my.add_class('disabled')
my.add_color("background", "background", -10)
value = my.get_value(for_display=True)
my.add(value)
my.handle_mode()
return super(TextAreaWdg,my).get_display()
class RadioWdg(BaseInputWdg):
def __init__(my,name=None, label=None):
super(RadioWdg,my).__init__(name,"input")
my.set_attr("type", "radio")
my.label = label
def set_checked(my):
my.set_attr("checked", "1")
def get_display(my):
my.set_attr("name", my.get_input_name())
my.add_class("spt_input")
# This is a little confusing. the option value is mapped to the
# html attribute value, however, the value from get_value() is the
# state of the element (on or off)
values = my.get_values(for_display=True)
# determine if this is checked
if my.name != None and len(values) != 0 \
and my.get_option("value") in values:
my.set_checked()
# convert all of the options to attributes
for name, option in my.options.items():
my.set_attr(name,option)
span = SpanWdg()
span.add(my.label)
my.add(span)
span.add_style("top: 3px")
span.add_style("position: relative")
return super(RadioWdg,my).get_display()
class CheckboxWdg(BaseInputWdg):
def __init__(my,name=None, label=None, css=None):
super(CheckboxWdg,my).__init__(name,"input", label)
my.set_attr("type", "checkbox")
my.label = label
my.css = css
my.add_class("spt_input")
def set_default_checked(my):
''' this is used for checkbox that has no value set'''
my.set_option("default", "on")
def set_checked(my):
my.set_option("checked", "1")
def is_checked(my, for_display=False):
# Checkbox needs special treatment when comes to getting values
values = my.get_values(for_display=for_display)
value_option = my._get_value_option()
# FIXME if values is boolean, it will raise exception
if value_option in values:
return True
else:
return False
#return my.get_value() == my._get_value_option()
def _get_value_option(my):
value_option = my.get_option("value")
if value_option == "":
value_option = 'on'
return value_option
def get_key(my):
class_path = Common.get_full_class_name(my)
key = "%s|%s" % (class_path, my.name)
return key
def check_persistent_values(my, cgi_values):
web = WebContainer.get_web()
if my.is_form_submitted():# and web.has_form_key(my.get_input_name):
# if the form is submitted, then always use the submitted value
if not my.persistence_obj:
return False
class_path = Common.get_full_class_name(my.persistence_obj)
key = "%s|%s" % (class_path, my.name)
setting = WidgetSettings.get_by_key(key, auto_create=False)
if setting == None:
return False
if not my.is_ajax(check_name=False):
my._set_persistent_values(cgi_values)
my.cached_values = cgi_values
return cgi_values
else:
return False
def get_display(my):
my.set_attr("name", my.get_input_name())
# This is a little confusing. the option value is mapped to the
# html attribute value, however, the value from get_value() is the
# state of the element (on or off) or the "value" option
values = my.get_values(for_display=True)
# for multiple checkboxes using the same name
if len(values) == 1:
# skip boolean
value = values[0]
if value and not isinstance(value, bool) and '||' in value:
values = value.split('||')
# determine if this is checked
value_option = my._get_value_option()
if values and len(values) != 0:
if value_option in values:
my.set_checked()
elif True in values: # for boolean columns
my.set_checked()
# convert all of the options to attributes
for name, option in my.options.items():
my.set_attr(name,option)
my.handle_behavior()
if not my.label:
return super(CheckboxWdg, my).get_display()
else:
cb = BaseInputWdg.get_class_display(my)
span = SpanWdg(cb, css=my.css)
span.add_style("vertical-align: center")
span.add(my.label)
return span
return super(CheckboxWdg,my).get_display()
def handle_behavior(my):
if my.persistence:
key = "%s|%s"%(Common.get_full_class_name(my.persistence_obj), my.name)
value = WidgetSettings.get_value_by_key(key)
if value:
my.set_value(value)
behavior = {"type" : "click_up",
'propagate_evt': True,
"cbjs_preaction":
"spt.input.save_selected(bvr, '%s','%s')"%(my.name, key)}
#"spt.api.Utility.save_widget_setting('%s',bvr.src_el.value)"%key}
#if my.change_cbjs_action:
# behavior['cbjs_action'] = my.change_cbjs_action
my.add_behavior(behavior)
class FilterCheckboxWdg(CheckboxWdg):
'''This composite checkbox acts as a filter and can be, for instance,
used in prefs area in TableWdg'''
def __init__(my,name=None, label=None, css=None ):
super(FilterCheckboxWdg,my).__init__(name, label=label, css=css)
#my.set_submit_onchange()
my.set_persistence()
def get_display(my):
# order matters here
return super(FilterCheckboxWdg, my).get_display()
class SelectWdg(BaseInputWdg):
SELECT_LABEL = "- Select -"
ALL_MODE = "all"
NONE_MODE = "NONE"
MAX_DEFAULT_SIZE = 20
# FIXME: this should not be here!!!
# dict for default project settings that will be auto-created if encountered.
# If not listed here, user will be prompted to add it himself
DEFAULT_SETTING = {'bin_type': 'client|dailies', 'bin_label': 'anim|tech', \
'shot_status': 'online|offline', 'note_dailies_context': 'dailies|review',\
'timecard_item': 'meeting|training|research'}
ARGS_KEYS = {
'values': {
'description': 'A list of values separated by | that determine the actual values of the selection',
'order': 0,
'category': 'Options'
},
'labels': {
'description': 'A list of values separated by | that determine the label of the selection',
'order': 1,
'category': 'Options'
},
'values_expr': {
'description': 'A list of values retrieved through an expression. e.g. @GET(prod/shot.code)',
'type': 'TextAreaWdg',
'order': 2
},
'labels_expr': {
'description': 'A list of labels retrieved through an expression. e.g. @GET(prod/shot.name)',
'type': 'TextAreaWdg',
'order': 3
},
'mode_expr': {
'description': 'Specify if it uses the current sObject as a starting point',
'type': 'SelectWdg',
'values': 'relative',
'empty': 'true',
'order': 4,
},
'empty': {
'description': 'The label for an empty selection',
#'default': '-- Select --',
'type': 'SelectWdg',
'values': 'true|false',
'order': 3,
'category': 'Options'
},
'default': {
'description': 'The default selection value in an edit form. Can be a TEL variable.',
'type': 'TextWdg',
'category': 'Options',
'order': 2,
},
'query': {
'description': 'Query shorthand in the form of <search_type>|<value_column>|<label_column>"'
}
}
def __init__(my, name=None, **kwargs):
my.kwargs = kwargs
css = kwargs.get('css')
label = kwargs.get('label')
my.sobjects_for_options = None
my.empty_option_flag = False
my.empty_option_label, my.empty_option_value = (my.SELECT_LABEL, "")
my.append_list = []
my.values = []
my.labels = []
my.has_set_options = False
my.css = css
my.append_widget = None
super(SelectWdg,my).__init__(name, type="select", label=label)
# add the standard style class
my.add_class("inputfield")
my.add_class("spt_input")
def get_related_type(my):
# In order to get the related type, the dom options need to have
# been processed
if not my.has_set_options:
my.set_dom_options(is_run=False)
return my.related_type
def add_empty_option(my, label='---', value= ''):
'''convenience function to an option with no value'''
my.empty_option_flag = True