• Publicity: Public Only All

xowiki-mode-procs.tcl

XoWiki - Mode procs

This file defines the following Objects and Classes: ::xowiki::Mode[i]

Location:
packages/xowiki/tcl/xowiki-mode-procs.tcl
Created:
2016-03-22
Author:
Gustaf Neumann
CVS Identification:
$Id: xowiki-mode-procs.tcl,v 1.3.2.2 2020/08/26 18:46:08 gustafn Exp $

Procedures in this file

Detailed information

Class ::xowiki::Mode (public)

 ::nx::Class ::xowiki::Mode[i]

Mode handler to set for the current session some application specific mode (like e.g. admin-mode, developer-mode, student-mode, training-mode, ...) Interface: - method get: obtain the current value (maybe default) - method set: force the mode to the provided value - method toggle: toggle current value

Partial Call Graph (max 5 caller/called nodes):
%3 ad_get_client_property ad_get_client_property (public) ad_set_client_property ad_set_client_property (public) Class ::xowiki::Mode Class ::xowiki::Mode Class ::xowiki::Mode->ad_get_client_property Class ::xowiki::Mode->ad_set_client_property

Testcases:
No testcase defined.

xowiki::Mode method get (public)

 <instance of xowiki::Mode[i]> get

Get the current mode, which might be set by the user or which might be obtained from the default method.

Partial Call Graph (max 5 caller/called nodes):
%3 ad_get_client_property ad_get_client_property (public) ad_set_client_property ad_set_client_property (public) xowiki::Mode instproc get xowiki::Mode instproc get xowiki::Mode instproc get->ad_get_client_property xowiki::Mode instproc get->ad_set_client_property

Testcases:
No testcase defined.

xowiki::Mode method set (public)

 <instance of xowiki::Mode[i]> set value

Set the mode to the specified value

Parameters:
value

Partial Call Graph (max 5 caller/called nodes):
%3 ad_set_client_property ad_set_client_property (public) xowiki::Mode instproc set xowiki::Mode instproc set xowiki::Mode instproc set->ad_set_client_property

Testcases:
No testcase defined.

xowiki::Mode method toggle (public)

 <instance of xowiki::Mode[i]> toggle

Switch state of the toggle

Partial Call Graph (max 5 caller/called nodes):
%3

Testcases:
No testcase defined.
[ hide source ] | [ make this the default ]

Content File Source

::xo::library doc {

  XoWiki - Mode procs

  @creation-date 2016-03-22
  @author Gustaf Neumann
  @cvs-id $Id: xowiki-mode-procs.tcl,v 1.3.2.2 2020/08/26 18:46:08 gustafn Exp $
}

namespace eval ::xowiki {

  nx::Class create ::xowiki::Mode {

    #
    # Mode handler to set for the current session some application
    # specific mode (like e.g. admin-mode, developer-mode,
    # student-mode, training-mode, ...)
    #
    # Interface:
    #   - method get: obtain the current value (maybe default)
    #   - method set: force the mode to the provided value
    #   - method toggle: toggle current value

    :method mode_name {} {
      return "mode-[::xo::cc package_id]-[self]"
    }

    :public method get {} {
      #
      # Get the current mode, which might be set by the user or which
      # might be obtained from the default method.
      #
      set default [:default]
      set mode_name [:mode_name]
      if {![ns_conn isconnected]} {
        return $default
      }
      if {[ad_get_client_property -cache_only t xowiki $mode_name] eq ""} {
        ad_set_client_property -persistent f xowiki $mode_name $default
      }
      return [ad_get_client_property -cache_only t xowiki $mode_name]
    }

    :public method toggle {} {
      #
      # Switch state of the toggle
      #
      set oldState [:get]
      :set [expr {!$oldState}]
    }

    :public method set {value:boolean} {
      #
      # Set the mode to the specified value
      #
      set mode_name [:mode_name]
      ad_set_client_property -persistent f xowiki $mode_name $value
    }
  }

  namespace eval ::xowiki::mode {}
  #
  # Create a sample "admin" mode handler.
  #
  ::xowiki::Mode create ::xowiki::mode::admin {
    :public object method default {} {
      # Admins are per default in admin-mode
      return [::xo::cc permission \
                  -object_id [xo::cc package_id] \
                  -privilege admin \
                  -party_id [xo::cc user_id]]
    }
  }
  #
  # one might create more such mode handler e.g. in a *-init.tcl file.
  #
}

::xo::library source_dependent
#
# Local variables:
#    mode: tcl
#    tcl-indent-level: 2
#    indent-tabs-mode: nil
# End: