| |
1 |
1 |
ad_library { |
| |
2 |
2 |
XoWiki - form classes |
| |
3 |
3 |
|
| |
4 |
4 |
@creation-date 2006-04-10 |
| |
5 |
5 |
@author Gustaf Neumann |
| |
6 |
6 |
@cvs-id $Id$ |
| |
7 |
7 |
} |
| |
8 |
8 |
|
| |
9 |
9 |
namespace eval ::xowiki { |
| |
10 |
10 |
|
| |
11 |
11 |
# |
| |
12 |
12 |
# Application specific forms |
| |
13 |
13 |
# |
| |
14 |
14 |
|
| |
15 |
15 |
Class create WikiForm -superclass ::Generic::Form \ |
| |
16 |
16 |
-parameter { |
| |
17 |
|
{field_list {item_id name title creator text description nls_language}} |
| |
|
17 |
{field_list {item_id name page_order title creator text description nls_language}} |
| |
18 |
18 |
{f.item_id {item_id:key}} |
| |
19 |
19 |
{f.name "="} |
| |
|
20 |
{f.page_order "="} |
| |
20 |
21 |
{f.title "="} |
| |
21 |
22 |
{f.creator "="} |
| |
22 |
23 |
{f.description "="} |
| |
23 |
24 |
{f.text "= richtext,editor=xinha"} |
| |
24 |
25 |
{validate |
| |
25 |
26 |
{{name {\[::xowiki::validate_name\]} {Another item with this name exists \ |
| |
26 |
27 |
already in this folder}}}} |
| |
27 |
28 |
{with_categories true} |
| |
28 |
29 |
{submit_link "view"} |
| |
29 |
30 |
{folderspec ""} |
| |
30 |
31 |
{autoname 0} |
| |
31 |
32 |
} -ad_doc { |
| |
32 |
33 |
Form Class for XoWiki Pages. |
| |
33 |
34 |
|
| |
34 |
35 |
You can manipulate the form elements shown by editing the field_list. The following elements are mandatory in field_list |
| |
35 |
36 |
and should never be left out: |
| |
36 |
37 |
<ul> |
| |
37 |
38 |
<li>name |
| |
38 |
39 |
<li>item_id |
| |
39 |
40 |
</ul> |
| |
40 |
41 |
|
| |
41 |
42 |
} |
| |
42 |
43 |
|
| |
43 |
|
WikiForm instproc show_page_order {} { |
| |
44 |
|
my instvar data |
| |
45 |
|
return [expr {[::xo::db::has_ltree] && [[$data package_id] get_parameter display_page_order 1]}] |
| |
46 |
|
} |
| |
47 |
|
|
| |
48 |
44 |
WikiForm instproc mkFields {} { |
| |
49 |
45 |
my instvar data autoname |
| |
50 |
46 |
set __fields "" |
| |
51 |
47 |
set field_list [my field_list] |
| |
52 |
|
if {[my show_page_order]} { |
| |
53 |
|
set field_list [linsert $field_list 2 page_order] |
| |
54 |
|
# todo: needed? |
| |
55 |
|
if {[$data istype ::xowiki::PageInstance]} { |
| |
56 |
|
set s [$data get_field_type page_order ""] |
| |
57 |
|
if {$s ne ""} { |
| |
58 |
|
my set f.page_order page_order:$s |
| |
59 |
|
} |
| |
60 |
|
} |
| |
61 |
|
} |
| |
62 |
|
if {$autoname} { |
| |
63 |
|
my f.name {name:text(hidden),optional} |
| |
64 |
|
} |
| |
65 |
48 |
|
| |
|
49 |
set show_page_order [[$data package_id] show_page_order] |
| |
|
50 |
if {!$show_page_order} { my f.page_order "= hidden" } |
| |
|
51 |
if {$autoname} { my f.name "= hidden"} |
| |
|
52 |
|
| |
66 |
53 |
foreach __field $field_list { |
| |
67 |
54 |
|
| |
68 |
55 |
# if there is no field spec, use the default from the slot definitions |
| |
69 |
56 |
set __spec [expr {[my exists f.$__field] ? [my set f.$__field] : "="}] |
| |
70 |
57 |
set __wspec [lindex $__spec 0] |
| |
71 |
58 |
|
| |
72 |
59 |
#my msg "$__field wspec=$__wspec, spec=$__spec" |
| |
73 |
60 |
# |
| |
74 |
61 |
# get first the information from the attribute definitions & given specs |
| |
75 |
62 |
# |
| |
76 |
63 |
if {[lindex $__wspec 0] eq "="} { |
| |
77 |
64 |
set f [$data create_form_field \ |
| |
78 |
65 |
-name $__field \ |
| |
79 |
66 |
-slot [$data find_slot $__field] \ |
| |
80 |
67 |
-spec [lindex $__spec 1] \ |
| |
81 |
68 |
] |
| |
82 |
69 |
|
| |
83 |
70 |
if {[$f istype ::xowiki::FormField::richtext] && |
| |
84 |
71 |
[my folderspec] ne ""} { |
| |
85 |
72 |
# insert the folder id into the spec for the |
|
| |
296 |
283 |
my update_references |
| |
297 |
284 |
return $item_id |
| |
298 |
285 |
} |
| |
299 |
286 |
|
| |
300 |
287 |
# |
| |
301 |
288 |
# PlainWiki Form |
| |
302 |
289 |
# |
| |
303 |
290 |
|
| |
304 |
291 |
Class create PlainWikiForm -superclass WikiForm \ |
| |
305 |
292 |
-parameter { |
| |
306 |
293 |
{f.text "= textarea,cols=80,rows=10"} |
| |
307 |
294 |
} |
| |
308 |
295 |
|
| |
309 |
296 |
# |
| |
310 |
297 |
# File Form |
| |
311 |
298 |
# |
| |
312 |
299 |
|
| |
313 |
300 |
Class create FileForm -superclass WikiForm \ |
| |
314 |
301 |
-parameter { |
| |
315 |
302 |
{html { enctype multipart/form-data }} \ |
| |
316 |
|
{field_list {item_id name text title creator description}} |
| |
|
303 |
{field_list {item_id name page_order text title creator description}} |
| |
317 |
304 |
{f.name "= optional,help_text=#xowiki.File-name-help_text#"} |
| |
318 |
305 |
{f.title "= optional"} |
| |
319 |
306 |
{f.text |
| |
320 |
307 |
{upload_file:file(file) |
| |
321 |
308 |
{label #xowiki.content#} |
| |
322 |
309 |
{html {size 30}} }} |
| |
323 |
310 |
{validate { |
| |
324 |
311 |
{upload_file {\[::xowiki::validate_file\]} {For new entries, \ |
| |
325 |
312 |
a upload file must be provided}} |
| |
326 |
313 |
{name {\[::xowiki::validate_name\]} {Another item with this name exists \ |
| |
327 |
314 |
already in this folder}} |
| |
328 |
315 |
}} |
| |
329 |
316 |
} |
| |
330 |
317 |
|
| |
331 |
318 |
|
| |
332 |
319 |
FileForm instproc get_uploaded_file {} { |
| |
333 |
320 |
my instvar data |
| |
334 |
321 |
#my log "--F... [ns_conn url] [ns_conn query] form vars = [ns_set array [ns_getform]]" |
| |
335 |
322 |
set upload_file [$data form_parameter upload_file] |
| |
336 |
323 |
# my log "--F... upload_file = $upload_file" |
|
| |
357 |
344 |
FileForm instproc new_data {} { |
| |
358 |
345 |
#my get_uploaded_file |
| |
359 |
346 |
return [next] |
| |
360 |
347 |
} |
| |
361 |
348 |
FileForm instproc edit_data {} { |
| |
362 |
349 |
#my get_uploaded_file |
| |
363 |
350 |
return [next] |
| |
364 |
351 |
} |
| |
365 |
352 |
|
| |
366 |
353 |
# {f.pub_date |
| |
367 |
354 |
# {pub_date:date,optional {format "YYYY MM DD HH24 MI"} {html {id date}} |
| |
368 |
355 |
# {after_html {<input type="button" |
| |
369 |
356 |
# style="height:23px; width:23px; background: url('/resources/acs-templating/calendar.gif');" |
| |
370 |
357 |
# onclick ="return showCalendarWithDateWidget('date', 'y-m-d');" /> Y-M-D} |
| |
371 |
358 |
# }} |
| |
372 |
359 |
# } |
| |
373 |
360 |
|
| |
374 |
361 |
Class create PodcastForm -superclass FileForm \ |
| |
375 |
362 |
-parameter { |
| |
376 |
363 |
{html { enctype multipart/form-data }} \ |
| |
377 |
|
{field_list {item_id name text title subtitle creator pub_date duration keywords |
| |
|
364 |
{field_list {item_id name page_order text title subtitle creator pub_date duration keywords |
| |
378 |
365 |
description}} |
| |
379 |
366 |
{validate { |
| |
380 |
367 |
{upload_file {\[::xowiki::validate_file\]} {For new entries, \ |
| |
381 |
368 |
a upload file must be provided}} |
| |
382 |
369 |
{name {\[::xowiki::validate_name\]} {Another item with this name exists \ |
| |
383 |
370 |
already in this folder}} |
| |
384 |
371 |
{duration {\[::xowiki::validate_duration\]} {Check duration and provide default}} |
| |
385 |
372 |
}} |
| |
386 |
373 |
} |
| |
387 |
374 |
|
| |
388 |
375 |
# {help_text {E.g. 9:16 means 9 minutes 16 seconds (if ffmpeg is installed and configured, it will get the value automatically)}} |
| |
389 |
376 |
|
| |
390 |
377 |
PodcastForm instproc to_timestamp {widgetinfo} { |
| |
391 |
378 |
if {$widgetinfo ne ""} { |
| |
392 |
379 |
foreach {y m day hour min} $widgetinfo break |
| |
393 |
380 |
set t [clock scan "${hour}:$min $m/$day/$y"] |
| |
394 |
381 |
return [clock format $t] |
| |
395 |
382 |
} |
| |
396 |
383 |
return "" |
| |
397 |
384 |
} |
|
| |
457 |
444 |
|
| |
458 |
445 |
ObjectForm instproc edit_request {item_id} { |
| |
459 |
446 |
my instvar data |
| |
460 |
447 |
#my f.name {{name:text {label #xowiki.Page-name#}}} |
| |
461 |
448 |
permission::require_permission \ |
| |
462 |
449 |
-party_id [ad_conn user_id] -object_id [$data set parent_id] \ |
| |
463 |
450 |
-privilege "admin" |
| |
464 |
451 |
next |
| |
465 |
452 |
} |
| |
466 |
453 |
|
| |
467 |
454 |
ObjectForm instproc edit_data {} { |
| |
468 |
455 |
[my data] initialize_loaded_object |
| |
469 |
456 |
next |
| |
470 |
457 |
} |
| |
471 |
458 |
|
| |
472 |
459 |
# |
| |
473 |
460 |
# PageTemplateForm |
| |
474 |
461 |
# |
| |
475 |
462 |
Class create PageTemplateForm -superclass WikiForm \ |
| |
476 |
463 |
-parameter { |
| |
477 |
|
{field_list {item_id name title creator text anon_instances description nls_language}} |
| |
|
464 |
{field_list { |
| |
|
465 |
item_id name page_order title creator text anon_instances description nls_language |
| |
|
466 |
}} |
| |
478 |
467 |
} |
| |
479 |
468 |
|
| |
480 |
469 |
# |
| |
481 |
470 |
# PageInstance Forms |
| |
482 |
471 |
# |
| |
483 |
472 |
|
| |
484 |
473 |
Class create PageInstanceForm -superclass WikiForm \ |
| |
485 |
474 |
-parameter { |
| |
486 |
|
{field_list {item_id name page_template description nls_language}} |
| |
|
475 |
{field_list {item_id name page_order page_template description nls_language}} |
| |
487 |
476 |
{f.page_template |
| |
488 |
477 |
{page_template:text(select) |
| |
489 |
478 |
{label "Page Template"} |
| |
490 |
479 |
{options \[xowiki::page_templates\]}} |
| |
491 |
480 |
} |
| |
492 |
481 |
{with_categories false} |
| |
493 |
482 |
} |
| |
494 |
483 |
PageInstanceForm instproc set_submit_link_edit {} { |
| |
495 |
484 |
my instvar folder_id data |
| |
496 |
485 |
set object_type [[$data info class] object_type] |
| |
497 |
486 |
#my log "-- data=$data cl=[$data info class] ot=$object_type" |
| |
498 |
487 |
set item_id [$data set item_id] |
| |
499 |
488 |
set page_template [$data form_parameter page_template] |
| |
500 |
489 |
if {[$data exists_query_parameter return_url]} { |
| |
501 |
490 |
set return_url [$data query_parameter return_url] |
| |
502 |
491 |
} |
| |
503 |
492 |
set link [::[$data set package_id] pretty_link [$data set name]] |
| |
504 |
493 |
my submit_link [export_vars -base $link {{m edit} page_template return_url item_id}] |
| |
505 |
494 |
# my log "-- submit_link = [my submit_link]" |
| |
506 |
495 |
} |
| |
507 |
496 |
|
| |
508 |
497 |
PageInstanceForm instproc new_data {} { |
| |
509 |
498 |
my instvar data |
| |
510 |
499 |
set item_id [next] |
| |
511 |
500 |
my set_submit_link_edit |
| |
512 |
501 |
return $item_id |
| |
513 |
502 |
} |
| |
514 |
503 |
|
| |
515 |
504 |
PageInstanceForm instproc edit_data {} { |
| |
516 |
505 |
return [next] |
| |
517 |
506 |
} |
| |
518 |
507 |
|
| |
519 |
508 |
Class create PageInstanceEditForm -superclass WikiForm \ |
| |
520 |
509 |
-parameter { |
| |
521 |
|
{field_list_top {item_id name title creator}} |
| |
|
510 |
{field_list_top {item_id name page_order title creator}} |
| |
522 |
511 |
{field_list_bottom {page_template description nls_language}} |
| |
523 |
512 |
{f.name "= inform"} |
| |
524 |
513 |
{f.page_template {page_template:text(hidden)}} |
| |
525 |
514 |
{f.nls_language {nls_language:text(hidden)}} |
| |
526 |
515 |
{with_categories true} |
| |
527 |
516 |
{textfieldspec {text(textarea),nospell {html {cols 60 rows 5}}}} |
| |
528 |
517 |
} |
| |
529 |
518 |
|
| |
530 |
519 |
PageInstanceEditForm instproc new_data {} { |
| |
531 |
520 |
my instvar data |
| |
532 |
521 |
set __vars {folder_id item_id page_template return_url} |
| |
533 |
522 |
set object_type [[$data info class] object_type] |
| |
534 |
523 |
#my log "-- cl=[[my set data] info class] ot=$object_type $__vars" |
| |
535 |
524 |
foreach __v $__vars {set $__v [$data from_parameter $__v] ""} |
| |
536 |
525 |
set item_id [next] |
| |
537 |
526 |
|
| |
538 |
527 |
set link [::[$data set package_id] pretty_link [$data set name]] |
| |
539 |
528 |
my submit_link [export_vars -base $link {{m edit} $__vars}] |
| |
540 |
529 |
# my log "-- submit_link = [my submit_link]" |
| |
541 |
530 |
return $item_id |
|
| |
632 |
621 |
foreach {content mime} $text break |
| |
633 |
622 |
if {$content eq ""} {return 1} |
| |
634 |
623 |
set clean_content $content |
| |
635 |
624 |
regsub -all "<br */?>" $clean_content "" clean_content |
| |
636 |
625 |
regsub -all "<p */?>" $clean_content "" clean_content |
| |
637 |
626 |
ns_log notice "--vaidate_form_content '$content' clean='$clean_content', stripped='[string trim $clean_content]'" |
| |
638 |
627 |
if {[string trim $clean_content] eq ""} { set text [list "" $mime]} |
| |
639 |
628 |
return 1 |
| |
640 |
629 |
} |
| |
641 |
630 |
|
| |
642 |
631 |
proc ::xowiki::validate_form_form {} { |
| |
643 |
632 |
upvar form form |
| |
644 |
633 |
if {$form eq ""} {return 1} |
| |
645 |
634 |
dom parse -simple -html [lindex $form 0] doc |
| |
646 |
635 |
$doc documentElement root |
| |
647 |
636 |
return [expr {[$root nodeName] eq "form"}] |
| |
648 |
637 |
} |
| |
649 |
638 |
|
| |
650 |
639 |
Class create FormForm -superclass ::xowiki::PageTemplateForm \ |
| |
651 |
640 |
-parameter { |
| |
652 |
|
{field_list {item_id name title creator text form form_constraints |
| |
|
641 |
{field_list {item_id name page_order title creator text form form_constraints |
| |
653 |
642 |
anon_instances description nls_language}} |
| |
654 |
643 |
{f.text "= richtext,height=200px"} |
| |
655 |
644 |
{f.form "= richtext,height=200px"} |
| |
656 |
645 |
{validate { |
| |
657 |
646 |
{name {\[::xowiki::validate_name\]} {Another item with this name exists \ |
| |
658 |
647 |
already in this folder}} |
| |
659 |
648 |
{text {\[::xowiki::validate_form_text\]} {From must contain a valid template}} |
| |
660 |
649 |
{form {\[::xowiki::validate_form_form\]} {From must contain an HTML form}} |
| |
661 |
650 |
}} |
| |
662 |
651 |
} |
| |
663 |
652 |
|
| |
664 |
653 |
FormForm instproc new_data {} { |
| |
665 |
654 |
my instvar data |
| |
666 |
655 |
set item_id [next] |
| |
667 |
656 |
|
| |
668 |
657 |
# provide unique ids and names, if form is provided |
| |
669 |
658 |
set text [$data set form] |
| |
670 |
659 |
if {$text ne ""} { |
| |
671 |
660 |
dom parse -simple -html [lindex $text 0] doc |
| |
672 |
661 |
$doc documentElement root |