dba/users 
                    library moduleURA
Summary
Add new pattern.
- Authors
 - Christian Grün, BaseX Team 2005-23, BSD License
 
Imports
This module is imported by 0 modules. It imports 3 modules.
Variables
Functions
4.1 dba:create
Arities: #3UR
dba:create
		  ( 
			$name as xs:string, $perm as xs:string, $pattern as xs:string ) as empty-sequence- name
asxs:stringusername - perm
asxs:stringpermission - pattern
asxs:stringpattern 
empty-sequenceredirection
Invoked by 0 functions from 0 modules
Annotations (6)
%updating | () | 
%rest:POST | () | 
%rest:path | ('/dba/pattern-add') | 
%rest:query-param | ('name','{$name}') | 
%rest:query-param | ('perm','{$perm}') | 
%rest:query-param | ('pattern','{$pattern}') | 
Source ( 14 lines)
function dba:create(
  $name     as xs:string,
  $perm     as xs:string,
  $pattern  as xs:string
) as empty-sequence() {
  try {
    user:grant($name, $perm, $pattern),
    util:redirect($dba:SUB, map { 'name': $name, 'info': 'Pattern was created.' })
  } catch * {
    util:redirect('pattern-add', map {
      'name': $name, 'perm': $perm, 'pattern': $pattern, 'error': $err:description
    })
  }
}4.2 dba:pattern-add
Arities: #4RA
dba:pattern-add
		  ( 
			$name as xs:string, $pattern as xs:string?, $perm as xs:string, $error as xs:string? ) as element(html)- name
asxs:stringusername - pattern
asxs:string?entered pattern - perm
asxs:stringchosen permission - error
asxs:string?error string 
element(html)page
Invoked by 0 functions from 0 modules
Annotations (7)
%rest:GET | () | 
%rest:path | ('/dba/pattern-add') | 
%rest:query-param | ('name','{$name}') | 
%rest:query-param | ('pattern','{$pattern}') | 
%rest:query-param | ('perm','{$perm}','write') | 
%rest:query-param | ('error','{$error}') | 
%output:method | ('html') | 
Source ( 43 lines)
function dba:pattern-add(
  $name     as xs:string,
  $pattern  as xs:string?,
  $perm     as xs:string,
  $error    as xs:string?
) as element(html) {
  html:wrap(map { 'header': ($dba:CAT, $name), 'error': $error },
    <tr>
      <td>
        <form action='pattern-add' method='post' autocomplete='off'>
          <h2>{
            html:link('Users', $dba:CAT), ' » ',
            html:link($name, $dba:SUB, map { 'name': $name }), ' » ',
            html:button('create', 'Add Pattern')
          }</h2>
          <input type='hidden' name='name' value='{ $name }'/>
          <table>
            <tr>
              <td>Pattern:</td>
              <td>
                <input type='text' name='pattern' value='{ $pattern }' id='pattern'/>
                { html:focus('pattern') }  
                <span class='note'>…support for <a target='_blank'
                  href='https://docs.basex.org/wiki/Commands#Glob_Syntax'>glob syntax</a>.</span>
                <div class='small'/>
              </td>
            </tr>
            <tr>
              <td>Permission:</td>
              <td>
                <select name='perm' size='3'>{
                  for $p in $options:PERMISSIONS[position() = 1 to 3]
                  return element option { attribute selected { }[$p = $perm], $p }
                }</select>
                <div class='small'/>
              </td>
            </tr>
          </table>
        </form>
      </td>
    </tr>
  )
}Namespaces
The following namespaces are defined:
| Prefix | Uri | 
|---|---|
| dba | dba/users 2 3 4 5 6 7 | 
| err | http://www.w3.org/2005/xqt-errors | 
| html | dba/html | 
| options | dba/options | 
| output | http://www.w3.org/2010/xslt-xquery-serialization | 
| rest | http://exquery.org/ns/restxq | 
| user | http://basex.org/modules/user | 
| util | dba/util | 
| xs | http://www.w3.org/2001/XMLSchema | 
6 RestXQ
Paths defined 2.
| Path | Method | Function | 
|---|---|---|
| /dba/pattern-add | GET | dba:pattern-add#4 | 
| /dba/pattern-add | POST | dba:create#3 | 
Source Code
(:~
 : Add new pattern.
 :
 : @author Christian Grün, BaseX Team 2005-23, BSD License
 :)
module namespace dba = 'dba/users';
import module namespace html = 'dba/html' at '../lib/html.xqm';
import module namespace options = 'dba/options' at '../lib/options.xqm';
import module namespace util = 'dba/util' at '../lib/util.xqm';
(:~ Top category :)
declare variable $dba:CAT := 'users';
(:~ Sub category :)
declare variable $dba:SUB := 'user';
(:~
 : Form for adding a new pattern.
 : @param  $name     username
 : @param  $pattern  entered pattern
 : @param  $perm     chosen permission
 : @param  $error    error string
 : @return page
 :)
declare
  %rest:GET
  %rest:path('/dba/pattern-add')
  %rest:query-param('name',    '{$name}')
  %rest:query-param('pattern', '{$pattern}')
  %rest:query-param('perm',    '{$perm}', 'write')
  %rest:query-param('error',   '{$error}')
  %output:method('html')
function dba:pattern-add(
  $name     as xs:string,
  $pattern  as xs:string?,
  $perm     as xs:string,
  $error    as xs:string?
) as element(html) {
  html:wrap(map { 'header': ($dba:CAT, $name), 'error': $error },
    <tr>
      <td>
        <form action='pattern-add' method='post' autocomplete='off'>
          <h2>{
            html:link('Users', $dba:CAT), ' » ',
            html:link($name, $dba:SUB, map { 'name': $name }), ' » ',
            html:button('create', 'Add Pattern')
          }</h2>
          <input type='hidden' name='name' value='{ $name }'/>
          <table>
            <tr>
              <td>Pattern:</td>
              <td>
                <input type='text' name='pattern' value='{ $pattern }' id='pattern'/>
                { html:focus('pattern') }  
                <span class='note'>…support for <a target='_blank'
                  href='https://docs.basex.org/wiki/Commands#Glob_Syntax'>glob syntax</a>.</span>
                <div class='small'/>
              </td>
            </tr>
            <tr>
              <td>Permission:</td>
              <td>
                <select name='perm' size='3'>{
                  for $p in $options:PERMISSIONS[position() = 1 to 3]
                  return element option { attribute selected { }[$p = $perm], $p }
                }</select>
                <div class='small'/>
              </td>
            </tr>
          </table>
        </form>
      </td>
    </tr>
  )
};
(:~
 : Creates a pattern.
 : @param  $name     username
 : @param  $perm     permission
 : @param  $pattern  pattern
 : @return redirection
 :)
declare
  %updating
  %rest:POST
  %rest:path('/dba/pattern-add')
  %rest:query-param('name',    '{$name}')
  %rest:query-param('perm',    '{$perm}')
  %rest:query-param('pattern', '{$pattern}')
function dba:create(
  $name     as xs:string,
  $perm     as xs:string,
  $pattern  as xs:string
) as empty-sequence() {
  try {
    user:grant($name, $perm, $pattern),
    util:redirect($dba:SUB, map { 'name': $name, 'info': 'Pattern was created.' })
  } catch * {
    util:redirect('pattern-add', map {
      'name': $name, 'perm': $perm, 'pattern': $pattern, 'error': $err:description
    })
  }
};