- Methods: All Methods Documented Methods Hide Methods
- Source: Display Source Hide Source
- Variables: Show Variables Hide Variables
Class Relations
::xo::Module create ::xowiki::utility
Methods (to be applied on the object)
change_page_order (scripted, public)
xowiki::utility change_page_order -from from -to to [ -clean clean ] \ -folder_id folder_id -package_id package_id \ [ -publish_status publish_status ]
Update page_order attributes for pages by renumbering and filling gaps.
- Switches:
- -from (required)
- list of page_orders before a move/insert operation
- -to (required)
- list of page_orders after a move/insert operation
- -clean (optional)
- list of page_orders for insert operations, to update the hierarchy from where items were moved to the new hierarchy.
- -folder_id (required)
- -package_id (required)
- -publish_status (optional, defaults to
"ready|live|expired"
)
- Testcases:
- No testcase defined.
#set from {1.2 1.3 1.4}; set to {1.3 1.4 1.2}; set clean {...} #set from {1.2 1.3 1.4}; set to {1.3 1.4 2.1 1.2}; set clean {2.1} #set from {1 2}; set to {1 1.2 2}; set clean {1.2 1.3 1.4} if {$from eq "" || $to eq "" || [llength $to]-[llength $from] > 1 || [llength $to]-[llength $from] < 0 } { ad_log warning "unreasonable request to change page_order from='$from', to='$to'" return } #ns_log notice "--cpo from=$from, to=$to, clean=$clean" set gap_renames [list] # # We distinguish two cases: # - pure reordering: length(to) == length(from) # - insert from another section: length(to) == length(from)+1 # if {[llength $to] == [llength $from]} { #ns_log notice "--cpo reorder" } elseif {[llength $clean] > 1} { #ns_log notice "--cpo insert" # # We have to fill the gap. First, find the newly inserted # element in $to. # foreach e $to { if {$e ni $from} { set inserted $e break } } if {![info exists inserted]} { error "invalid 'to' list (no inserted element detected)" } # # Compute the remaining list. # set remaining [list] foreach e $clean { if {$e ne $inserted} { lappend remaining $e } } # # Compute rename commands for it. # set gap_renames [::xowiki::utility page_order_renames -parent_id $folder_id -publish_status $publish_status -start [lindex $clean 0] -from $remaining -to $remaining] foreach {page_id item_id name old_page_order new_page_order} $gap_renames { ns_log notice "--cpo gap $page_id (name) rename $old_page_order to $new_page_order" } } # # Compute the rename commands for the drop target. # set drop_renames [::xowiki::utility page_order_renames -parent_id $folder_id -publish_status $publish_status -start [lindex $from 0] -from $from -to $to] #ns_log notice "--cpo drops l=[llength $drop_renames]" foreach {page_id item_id name old_page_order new_page_order} $drop_renames { #ns_log notice "--cpo drop $page_id ($name) rename $old_page_order to $new_page_order" } # # Perform the actual renames. # set temp_obj [::xowiki::Page new -name dummy -volatile] set slot [$temp_obj find_slot page_order] ::xo::dc transaction { foreach {page_id item_id name old_page_order new_page_order} [concat $drop_renames $gap_renames] { #ns_log notice "--cpo UPDATE $page_id new_page_order $new_page_order" $temp_obj item_id $item_id $temp_obj update_attribute_from_slot -revision_id $page_id $slot $new_page_order ::xo::xotcl_object_cache flush $item_id ::xo::xotcl_object_cache flush $page_id } } # # Flush the page fragment caches (page fragments based on # page_order might be sufficient). ::$package_id flush_page_fragment_cache -scope agg
formCSSclass (scripted, public)
xowiki::utility formCSSclass form_name
Obtain CSS class name for a form from its name
- Parameters:
- form_name (required)
- Testcases:
- link_tests, create_form_with_form_instance
set CSSname $form_name regexp {^..:(.*)$} $CSSname _ CSSname regsub {[.].*$} $CSSname "" CSSname return "Form-$CSSname"
publish_status_next_state (scripted, private)
xowiki::utility publish_status_next_state publish_status
Determine next publish status and return dict containing CSSclass and next state.
- Parameters:
- publish_status (required)
- Testcases:
- No testcase defined.
if {$publish_status eq "ready"} { set CSSclass green set state "production" } elseif {$publish_status eq "expired"} { set CSSclass black set state "production" } else { set CSSclass red set state "ready" } return [list CSSclass $CSSclass state $state]
user_is_active (scripted, public)
xowiki::utility user_is_active [ -asHTML on|off ] uid
Tell whether a user is active according to the Request Monitor.
- Switches:
- -asHTML (optional, boolean, defaults to
"false"
) - when true, the proc will return an HTML rendering of the user information.
- -asHTML (optional, boolean, defaults to
- Parameters:
- uid (required)
- the user id
- Returns:
- boolean or HTML according to the 'asHTML' flag.
- Testcases:
- No testcase defined.
if {[info commands ::throttle] ne "" && [::throttle info methods user_is_active] ne ""} { set active [throttle user_is_active $uid] if {$asHTML} { array set color {1 green 0 red} array set state {1 active 0 inactive} return "<span class='$state($active)' style='background: $color($active);'> </span>" } else { return $active } } else { ns_log notice "user_is_active requires xotcl-request monitor in a recent version" return 0 }
- Methods: All Methods Documented Methods Hide Methods
- Source: Display Source Hide Source
- Variables: Show Variables Hide Variables