Quantcast

Language support in knop_grid

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Language support in knop_grid

Jolle Carlestam-2
I noticed that knop_grid have hardcoded language strings.  
Specifically Search and Show all.

So pending the knop_string I fiddled some in the code. Added an  
optional param -language and some handling to set language to what's  
specified there.

HDB
Jolle

Here's code:

<?LassoScript

define_type: 'grid',
        -namespace='mt_';
// -prototype;

/*

CHANGE NOTES
2007-03-08 JC Added support an optional param Language to handle  
hardcoded strings in quicksearch
2007-03-01 JS Added support for FileMaker with quicksearch (untested)
2007-03-01 JS Changed all texts to English
2007-02-07 JS Removed classs="first" and class="notopborder" since  
CSS border-collapse: collapse; eliminates the need
2007-02-05 JS The -keyvalue parameter for url edit links can be given  
another name by specifying -keyparamname in addfield
2007-01-31 JS ->addfield: #value# can be used in -url, as a way to  
provide mailto links etc in lists
2007-01-30 JS Sortable columns now thave three states instead of two:  
sorted ascending, sorted descending and unsorted.
2007-01-30 JS Improvements to quicksearch, to emulate "word begins  
with"  searches
2007-01-26 JS Added support for quicksearch field in grid header.  
Specify -quicksearch at ->oncreate, and tell what fields to search by  
specifying -quicksearch for those fields at ->addfield.
                                Fields can be search only (no display) by leaving out name and  
label. All specified fields are searched word for word of thew search  
string.
                                Use ->quicksearch to get the search parameters (optionally -sql)
2007-01-26 JS Added ->urlargs to get a querystring with all "-" GET  
params, except those in optional -except string or array parameter.
2007-01-22 JS Adjustments to highlighting and "(redigera)"-link for  
records with empty values in the linked field
2007-01-19 JS Added href titles to sort links and prevnext links
2007-01-19 JS Corrected sortparams when no sortfield is specified
2007-01-19 JS Addded go to first page, go to last page in footer
2007-01-19 JS Added member tag page_skiprecords to help correcting  
out of bounds page numbers
2007-01-19 JS Added member tag lastpage
2007-01-18 JS Support for highlighting of affected record after edit  
or update (class name highlight)
2007-01-17 JS Added addfield: -template

TODO
Make texts in header and footer configurable

*/
        local: 'version'='2007-03-08';
        define_tag: 'help';
                return:
'mt_grid, a custom type to handle data grids (record listings).

Version ' + (self -> 'version') + '


-> oncreate
        required: -database type: -database // database object that the grid  
object will interact with
        optional: -nav type: -nav // optional navigation object to  
interact with
        optional: -quicksearch // flag or value, optional quick search  
box, if string is provided then that is used as label text
        optional: -language // value, if used sets hardcoded string  
values to the specified language. Defaults to English
       
-> onassign // needed to restore references when ctype is defined as  
prototype
        required: -value

-> addfield // Adds a column to the record listing
        optional: -name // Name of the field
        optional: -label // Column heading
        optional: -dbfield // corresponding database field name (name is  
used if dbfield is not specified)
        optional: -width // pixels (CSS width)
        optional: -class // CSS class name to use for the column cells
        optional: -url // field will be linked with this url as base. Can  
contain #value# for example to create clickable email links.
        optional: -keyparamname // param name to use instead of the default -
keyvalue for edit links
        optional: -defaultsort // flag, this field will be the default sort  
field
        optional: -nosort // flag, the field header should not be clickable  
for sort
        optional: -template // either string to format values or map  
containing templates to display individual values in different ways,  
use -default to display unknown values, use #value# to insert the  
actual field value in the template
        optional: -quicksearch // flag, if specified, the field will be used  
for search with quicksearch
       
-> sortparams // Returns a Lasso-style pair array with sort  
parameters to use in the search inline.
        optional: -sql // flag, return an SQL string for the sort parameters  
instead.

-> quicksearch // Returns a pair array with fieldname=value
        optional: -sql // flag, return an SQL string for the search  
parameters instead.

-> urlargs // returns all get params that begin with - as a query  
string, for internal use in links in the grid
        optional: -except // exclude these parameters (string or array)
        optional: -prefix // for example ? or &amp; to include at the  
beginning of the querystring
        optional: -suffix // for example &amp; to include at the end of the  
querystring

-> renderhtml // Outputs the complete record listing.
                                // Calls renderheader and renderfooter as well.
                                // If 10 records or more are shown, renderfooter is added also  
just below the header.
        optional: -inlinename // If not specified, inlinename from the  
connected database object is used

-> renderheader // Outputs the header of the grid with the column  
headings.
                                // Automatically included by ->renderhtml
        optional: -start // flag, also output opening <table> tag

-> renderfooter // Outputs the footer of the grid with the prev/next  
links and information about found count
                                // Automatically included by ->renderhtml
        optional: -end // flag, also output closing </table> tag

-> page // Returns the current page number

-> lastpage // Returns the number of the last page for the found  
records

-> page_skiprecords // converts page value to a skiprecords value to  
use in search
        required: -maxrecords type: -integer // Needed to be able to do the  
calculation. Maxrecords_value can not be taken from the database  
object since taht value is not available until aftetr performing the  
search

-> trace // outputs debug information
        optional: -html // formats debug info with <be> linebreaks

';
        /define_tag;

        // instance variables
        local: 'fields'=array,
                'dbfieldmap'=map,
                'sortfield'=string,
                'defaultsort'=string,
                'page'=integer,
                'sortdescending'=false,
                'database'=null,
                'nav'=null,
                'debug_trace'=array,
                'quicksearch'=string,
                'quicksearch_form',
                'quicksearch_form_reset',
                'quicksearch_fields'=array;

               
        define_tag: 'oncreate',
                -required='database', -type='database', // database object that the  
grid object will interact with
                -optional='nav', -type='nav', // optional navigation object to  
interact with
                -optional='quicksearch', // optional quick search box, if string  
is provided then that is used as label text
                -optional='language'; // optional language setting. If not used  
default is English
               
                // the following params are stored as reference, so the values of  
the params can be altered after adding a field simply by changing the  
referenced variable.
                iterate: (array:
                        'database', 'nav'), (local: 'param');
                        (local_defined: #param) ? (self -> #param = @(local: #param));
                /iterate;
               
                local: 'clientparams'=client_getparams;
                #clientparams -> (merge: client_postparams);
                (self -> 'sortfield') = (#clientparams >> -sort ? (#clientparams ->  
(find: -sort) -> first -> value) | string);
                (self -> 'sortdescending') = (#clientparams >> -desc);
                (self -> 'page') = (#clientparams >> -page ? (integer:  
(#clientparams -> (find: -page) -> first -> value)) | 1);
                (self -> 'page') < 1 ? (self -> 'page') = 1;

                if: (local_defined: 'language');
                        select: #language;
                                case:'English';
                                        local:'searchLabel' = 'Search',
                                                'showLabel' = 'Show all';
                                case:'Swedish';
                                        local:'searchLabel' = 'Sök',
                                                'showLabel' = 'Visa alla';
                                case;
                                        local:'searchLabel' = 'Search',
                                                'showLabel' = 'Show all';
                        /select;
                else;
                        local:'searchLabel' = 'Search',
                                'showLabel' = 'Show all';
                /if;

                if: (local_defined: 'quicksearch');
                        if: #quicksearch != '';
                                (self -> 'quicksearch') = #quicksearch;
                        else;
                                (self -> 'quicksearch') = 'Quicksearch';
                        /if;
                        (self -> 'quicksearch_form') = (knop_form: -name='quicksearch', -
action='./', -method='get', -template='#field#\n', -noautoparams);
                        (self -> 'quicksearch_form_reset') = (knop_form: -
name='quicksearch_reset', -action='./', -method='get', -
template='#field#\n', -noautoparams);
                        local: 'autosavekey'=server_name + response_path;
                        if: (self -> 'nav') -> type =='nav' && (self -> 'nav') ->  
'navmethod'=='param';
                                (self -> 'quicksearch_form') -> (addfield: -type='hidden', -
name='-path', -value=((self -> 'nav') -> path));
                                (self -> 'quicksearch_form_reset') -> (addfield: -type='hidden', -
name='-path', -value=((self -> 'nav') -> path));
                                #autosavekey -> (removetrailing: '/');
                                #autosavekey += '/' + ((self -> 'nav') -> path);
                        /if;
                        if: (self -> 'sortfield') != '';
                                (self -> 'quicksearch_form') -> (addfield: -type='hidden', -
name='-sort', -value=(self -> 'sortfield'));
                                (self -> 'quicksearch_form_reset') -> (addfield: -type='hidden', -
name='-sort', -value=(self -> 'sortfield'));
                                if: (self -> 'sortdescending');
                                        (self -> 'quicksearch_form') -> (addfield: -type='hidden', -
name='-desc');
                                        (self -> 'quicksearch_form_reset') -> (addfield: -type='hidden',  
-name='-desc');
                                /if;
                        /if;
                        (self -> 'quicksearch_form') -> (addfield: -type='search', -name='-
q', -hint=(self -> 'quicksearch'),
                                -size=15, -id='quicksearch_q', -raw='autosave="' + #autosavekey +  
'" results="10"');
                        (self -> 'quicksearch_form') -> (addfield: -type='submit', -
name='s', -value= #searchLabel);
                        if: #clientparams >> -q;
                                (self -> 'quicksearch_form') -> (setvalue: '-q'=(#clientparams ->  
(find: -q) -> first -> value));
                                (self -> 'quicksearch_form_reset') -> (addfield: -type='submit', -
name='a', -value= #showLabel);
                        else;
                                (self -> 'quicksearch_form_reset') -> (addfield: -type='submit', -
name='a', -value= #showLabel, -disabled);
                        /if;
                /if;
        /define_tag;

        define_tag: 'onassign', -required='value'; // needed to restore  
references when ctype is defined as prototype
                // recreate references here
                (self->'database') = @(#value -> 'database');
                (self->'nav') = @(#value -> 'nav');
        /define_tag;

        define_tag: 'onconvert';
        /define_tag;
       
        define_tag: '_unknowntag';
                return: 'Member tag -> ' + Tag_name + ' not known';
        /define_tag;
       
       
        define_tag: 'addfield',
                -optional='name',
                -optional='label',
                -optional='dbfield', // corresponding database field name (name is  
used if dbfield is not specified)
                -optional='width', // pixels (css width)
                -optional='class',
                -optional='url', // field will be linked with this url as base
                -optional='keyparamname',// param name to use instead of the  
default -keyvalue for edit links
                -optional='defaultsort', // this field will be the default sort field
                -optional='nosort', // the field header should not be clickable  
for sort
                -optional='template', // either string to format values or map  
containing templates to display individual values in different ways,  
use -default to display unknown values, use #value# to insert the  
actual field value in the template
                -optional='quicksearch'; // if specified, the field will be used  
for search with quicksearch
               
                fail_if: (local_defined: 'template') && #template -> type !=  
'string' && #template -> type != 'map', -1, 'Template must be either  
string or map';
                local: 'field'=map;
                iterate: (array: 'name', 'class', 'url', 'keyparamname', 'width'),  
(local: 'param');
                        (local_defined: #param) ? (#field -> (insert: #param = (local:  
#param)));
                /iterate;
                #field !>> 'keyparamname' ? #field -> (insert: 'keyparamname' = -
keyvalue);
               
                if: (local_defined: 'template');
                        #field -> (insert: 'template'=(#template -> type == 'string' ?  
(map: -default=#template) | #template));
                /if;
                if: (local_defined: 'name');
                        #field -> (insert: 'label'=( (local_defined: 'label') ? #label |  
#name ) );
                        #field -> (insert: 'dbfield'=( (local_defined: 'dbfield') ?  
#dbfield | #name ) );
                        #field -> (insert: 'nosort'=(local_defined: 'nosort'));
                        if: local_defined: 'defaultsort' && !(local_defined: 'nosort') &&  
(self -> 'defaultsort') == '';
                                (self -> 'defaultsort') = #name;
                                if: (self -> 'sortfield') == '';
                                        (self -> 'sortfield') = (self -> 'defaultsort');
                                /if;
                        /if;
                        (self -> 'dbfieldmap') -> (insert: #name = ((local_defined:  
'dbfield') ? #dbfield | #name));
                /if;
                (local_defined: 'quicksearch') ? (self -> 'quicksearch_fields') ->  
(insert: ((local_defined: 'dbfield') ? #dbfield | (local: 'name')));
               
                if: local_defined: 'name' || local_defined: 'label';
                        (self -> 'fields') -> (insert: #field);
                /if;
        /define_tag;
       
        define_tag: 'sortparams',
                -optional='sql';
                        if: local_defined: 'sql';
                                fail_if: (self -> 'database') -> 'isfilemaker', 7009, '-sql can  
not be used with FileMaker';
                                (self -> 'sortfield') == '' ? return;
                                local: 'output'=' ORDER BY ';
                                if: (self -> 'dbfieldmap') >> (self -> 'sortfield');
                                        #output += ((self -> 'dbfieldmap') -> (find: (self ->  
'sortfield')));
                                else;
                                        #output += (self -> 'sortfield');
                                /if;
                                if: (self -> 'sortdescending');
                                        #output += ' DESC';
                                /if;
                        else;
                                local: 'output'=array;
                                (self -> 'sortfield') == '' ? return: @#output;
                                if: (self -> 'dbfieldmap') >> (self -> 'sortfield');
                                        #output -> (insert: -sortfield=(self -> 'dbfieldmap') -> (find:  
(self -> 'sortfield')) );
                                else;
                                        #output -> (insert: -sortfield=(self -> 'sortfield'));
                                /if;
                                if: (self -> 'sortdescending');
                                        #output -> (insert: -sortorder='descending');
                                /if;
                        /if;
                return: @#output;
        /define_tag;

        define_tag: 'quicksearch',
                -optional='sql';
                // Returns a pair array with fieldname=value, or optionally SQL  
string to be used in an update inline.
                local: 'output'=array,
                        'output_temp'=array,
                        '_sql'=(local_defined: 'sql'),
                        'wordseparators'=',.- ("',
                        'fieldvalue', 'onevalue', 'field', 'wordseparator';
                fail_if: #_sql && (self -> 'database') -> 'isfilemaker', 7009, '-
sql can not be used with FileMaker';

                #wordseparators = #wordseparators -> (split: '');
                if: (self -> 'quicksearch_form') -> type != 'form';
                        if: #_sql;
                                return: string;
                        else;
                                return: array;
                        /if;
                /if;
                #fieldvalue = string: ((self -> 'quicksearch_form') -> (getvalue: '-
q'));
                if: #fieldvalue != '';
                        if: (self -> 'database') -> 'isfilemaker';
                                #output -> (insert: -logicaloperator='or');
                                iterate: (self -> 'quicksearch_fields'), #field;
                                        #output -> (insert:  #field = #fieldvalue);
                                /iterate;
                        else;
                                // search each word separately
                                #fieldvalue = #fieldvalue -> (split: ' ');
                                iterate: #fieldvalue, #onevalue;
                                        #output_temp = array;
                                        iterate: (self -> 'quicksearch_fields'), #field;
                                                if: #_sql;
                                                        #output_temp -> (insert:  (encode_sql: #field )
                                                                + ' LIKE "' + (encode_sql: #onevalue ) + '%"');
                                                        // basic emulation of "word begins with"
                                                        iterate: #wordseparators, #wordseparator;
                                                                #output_temp -> (insert:  (encode_sql: #field )
                                                                        + ' LIKE "%' + (encode_sql: #wordseparator + #onevalue ) +  
'%"');
                                                        /iterate;
                                                else;
                                                        #output_temp -> (insert:  -op='bw');
                                                        #output_temp -> (insert:  #field = #onevalue );
                                                        if: !(self -> 'database' -> 'isfilemaker');
                                                                // this variant is not needed for FileMaker since it already  
searches with "word begins with" as default #output_temp ->  
(insert:  -op='cn');
                                                                iterate: #wordseparators, #wordseparator;
                                                                        #output_temp -> (insert:  -op='cn');
                                                                        #output_temp -> (insert:  #field = #wordseparator +  
#onevalue );
                                                                /iterate;
                                                        /if;
                                                /if;
                                        /iterate;
                                        if: #_sql;
                                                if: #output_temp -> size > 1;
                                                        #output_temp = '(' + #output_temp -> (join: ' OR ') + ')';
                                                else;
                                                        #output_temp = #output_temp -> first;
                                                /if;
                                                #output -> (insert: #output_temp);
                                        else;
                                                if: #output_temp -> size > 2;
                                                        #output_temp -> (insert: -opbegin='or', 1);
                                                        #output_temp -> (insert: -opend='or');
                                                /if;
                                                #output -> (merge: #output_temp);
                                        /if;
                                /iterate;
                               
                                if: #_sql;
                                        if: #output -> size;
                                                #output = '(' + #output -> (join: ' AND ') + ')';
                                        else;
                                                #output = string;
                                        /if;
                                else;
                                        if: #output -> size;
                                                #output -> (insert: -opbegin='and', 1);
                                                #output -> (insert: -opend='and');
                                        /if;
                                /if;
                        /if; // isfilemaker
                /if; // #fieldvalue != ''
                return: @#output;
        /define_tag;
       
        define_tag: 'urlargs', // returns all get params that begin with -  
as a query string
                -optional='except', -copy,
                -optional='prefix', // for example ? or &amp; to include at the  
beginning of the querystring
                -optional='suffix'; // for example &amp; to include at the end of  
the querystring
                local: 'output'=array, 'param';
                local: 'clientparams'=client_getparams;

                !(local_defined: 'except') ? local: 'except'=array;
                #except -> type != 'array' ? #except = array: #except;
               
                iterate: #clientparams, #param;
                        if: #param -> type == 'pair';
                                if: #param -> name -> (beginswith: '-') && #except !>> #param ->  
name;
                                        #output -> (insert: (#param -> name) + '=' + (#param -> value));
                                /if;
                        else; // just a string param (no pair)
                                if: #param -> (beginswith: '-') && #except !>> #param;
                                        #output -> (insert: #param);
                                /if;
                        /if;
                /iterate;
                if: #output -> size;
                        return: (local: 'prefix') + (#output -> (join: '&amp;')) + (local:  
'suffix');
                /if;

        /define_tag;
       
       
        define_tag: 'renderhtml',
                -optional='inlinename';
                local: '_inlinename'=string,
                        'output'=string,
                        'fields'=(self -> 'fields'),
                        'field'=string,
                        'keyfield'=null,
                        'affectedrecord_keyvalue'=null,
                        'record_loop_count'=integer,
                        'db'=@(self -> 'database'),
                        'nav'=@(self -> 'nav'),
                        'dbfieldmap'=@(self -> 'dbfieldmap'),
                        'classarray'=array,
                        'fieldname'=string,
                        'value'=string,
                        'keyparamname',
                        'url';
                if: (local: 'inlinename')!='';
                        #_inlinename = #inlinename;
                else: #db -> type == 'database';
                        #_inlinename=#db -> 'inlinename';
                        #keyfield=#db -> 'keyfield';
                        #affectedrecord_keyvalue = #db -> 'affectedrecord_keyvalue';
                /if;
                #output += (self -> (renderheader: -start));
                if: #db -> shown_count >= 10;
                        #output += (self -> renderfooter);
                /if;
                #output += '<tbody>';
                records: -inlinename=#_inlinename;
                        #record_loop_count = loop_count;
                        #output += '\n<tr>';
                        iterate: #fields, #field;
                                #fieldname = (#dbfieldmap -> (find: (#field -> (find: 'name'))));
                                #keyparamname = (#field -> (find: 'keyparamname'));
                                #value=(field: #fieldname);
                                if: #field -> (find: 'template') -> type == 'map';
                                        if: #field -> (find: 'template') >> #value;
                                                #value = #field -> (find: 'template') -> (find: #value);
                                        else: #field -> (find: 'template') >> -default;
                                                #value = #field -> (find: 'template') -> (find: -default);
                                        else;
                                                // show fieldvalue as is
                                        /if;
                                        // substitute field value in the display template
                                        #value -> (replace: '#value#', (field: #fieldname));
                                /if;
                                #classarray=array;
                                if:  #affectedrecord_keyvalue == (field: #keyfield) && (field:  
#keyfield) != '';
                                        // hightlight affected row
                                        #classarray -> (insert: 'highlight');
                                else;
                                        (#record_loop_count - 1)  % 2 == 0 ? #classarray -> (insert:  
'even');
                                /if;
                                #output += '<td';
                                if: #classarray -> size;
                                        #output += ' class="' + #classarray -> (join: ' ') + '"';
                                /if;
                                #output += '>';
                                if: (#field -> (find: 'url')) != '';
                                        #url = (#field -> (find: 'url'));
                                        if: #nav -> type == 'nav' && #url !>> '#value#';
                                                #output += '<a href="' + (#nav -> (url: -path=#url,
                                                        #keyparamname=(field: #keyfield),
                                                        -urlargs=(self -> (urlargs: -except=(array: -path,  
#keyparamname)))));
                                                #output += '">' +  #value
                                                        // show something to click on even if the field is empty
                                                        + ((string_findregexp: #value, -find='\\w*') -> size == 0 ?  
'(edit)')
                                                        + '</a>';
                                        else;
                                                #url -> (replace: '#value#', (field: #fieldname));
                                                #output += '<a href="' + #url + '"';
                                                #url -> (beginswith: 'http://') || #url -> (beginswith:  
'https://') || #url -> (beginswith: 'mailto:')
                                                        ? #output += ' class="ext"';
                                                #output += '>' +  #value + '</a>';
                                        /if;
                                else;
                                        #output += #value;
                                /if;
                                #output += '</td>\n';
                        /iterate;
                        #output += '</tr>\n';
                /records;
                #output += '</tbody>\n';
                #output += (self -> (renderfooter: -end));
        return: @#output;
        /define_tag;
       
        define_tag: 'renderheader',
                -optional='start';
                local: 'output'=string,
                        'db'=@(self -> 'database'),
                        'nav'=@(self -> 'nav'),
                        'fields'=@(self -> 'fields'),
                        'field'=string,
                        'classarray'=array;
                (local_defined: 'start') ? #output += '<table>';
                #output += '<thead>\n<tr>';
                if: (self -> 'quicksearch_form') -> type == 'form';
                        #output += '<th colspan="' + (#fields -> size) + '"  
class="quicksearch';
                                ((self -> 'quicksearch_form') -> (getvalue: '-q') != '') ?  
#output += ' highlight';
                        #output += '">';
                        #output += (self -> 'quicksearch_form') -> renderform;
                        if: (self -> 'quicksearch_form_reset') -> type =='form';
                                #output += (self -> 'quicksearch_form_reset') -> renderform;
                        /if;
                        #output += '</th></tr>\n<tr>';
                /if;
                iterate: #fields, #field;
                        #classarray=array;
                        //(self -> 'quicksearch_form') -> type == 'form' ? #classarray ->  
(insert: 'notopborder');
                        (self -> 'sortfield') == (#field -> (find: 'name')) && !(#field ->  
(find: 'nosort')) ? #classarray -> (insert: 'sort');
                        #output += '<th';
                        if: #field -> (find: 'width') > 0;
                                #output += ' style="width: ' + (integer: #field -> (find:  
'width')) + 'px;"';
                        /if;
                        if: #classarray -> size;
                                #output += ' class="' + #classarray -> (join: ' ') + '"';
                        /if;
                        #output += '>';
                        if: (#field -> (find: 'nosort'));
                                #output += '<div>' + (#field -> (find: 'label')) '</div>';
                        else;
                                if: (#classarray >> 'sort' && (self -> 'sortdescending'));
                                        // create link to change to unsorted
                                        #output += '<a href="./'
                                                + (self -> (urlargs: -except=(array: -sort, -desc, -page), -
prefix='?')) + '"'
                                                + ' title="Unsort">';
                                else;
                                        // create link to toggle sort mode
                                        #output += '<a href="./?-sort=' + (#field -> (find: 'name'))
                                                + (#classarray >> 'sort' && !(self -> 'sortdescending') ?  
'&amp;-desc')
                                                + (self -> (urlargs: -except=(array: -sort, -desc, -page), -
prefix='&amp;')) + '"'
                                                + ' title="' + (#classarray >> 'sort'
                                                        ? 'Change sort order to '
                                                                + ((self -> 'sortdescending') ? 'ascending' | 'descending')
                                                        | 'Sort ascending by ' + (encode_html: (#field -> (find:  
'label'))) ) + '">';
                                /if;
                                #output += (#field -> (find: 'label'));
                                if: (string_findregexp: (#field -> (find: 'label')), -find='\\S')  
-> size == 0;
                                        #output += '&nbsp;'; // to show sort link as block element  
properly even for empty label
                                /if;
                                if: #classarray >> 'sort';
                                        #output += ' <span class="sortmarker"> ' + ((self ->  
'sortdescending') ? '&#9660;' | '&#9650;') + '</span>';
                                /if;
                                #output += '</a>';
                         /if;
                         #output += '</th>\n';
                /iterate;
                #output += '</tr></thead>\n';
                return: @#output;
        /define_tag;

        define_tag: 'renderfooter',
                -optional='end';
                // unicode symbols http://www.alanwood.net/unicode/ 
geometric_shapes.html
                local: 'output'=string,
                        'db'=@(self -> 'database'),
                        'nav'=@(self -> 'nav'),
                        'fields'=@(self -> 'fields'),
                        'field'=string;
                #output += '<tr><th colspan="' + (#fields -> size) + '"  
class="footer first' + (!(local_defined: 'end') &&false? '  
notopborder') + '">';
               
                if: (self -> 'page') > 1;
                        #output += ' <a href="?' + (self -> (urlargs: -except=(array: -
page), -suffix='&amp;'))
                                + '-page=1" class="prevnext"'
                                + ' title="Go to first page">|&#9668;</a> ';

                        #output += ' <a href="?' + (self -> (urlargs: -except=(array: -
page), -suffix='&amp;'))
                                + '-page=' + ((self -> 'page') - 1)
                                + '" class="prevnext"'
                                + ' title="Go to previous page">&#9668;&#9642;&#9642;</a> ';
                else;
                        #output += ' <span class="prevnext dim">|&#9668;</span> <span  
class="prevnext dim">&#9668;&#9642;&#9642;</span> ';
                /if;
                if: #db -> found_count > #db -> shown_count;
                        #output += #db -> shown_first + ' - ' #db -> shown_last + ' of ';
                /if;
                #output += #db -> found_count + ' found';
                if: (#db -> shown_last) < (#db -> found_count);
                        #output += ' <a href="?' + (self -> (urlargs: -except=(array: -
page), -suffix='&amp;'))
                                + '-page=' + ((self -> 'page') + 1) + '" class="prevnext"'
                                + ' title="Go to next page">&#9642;&#9642;&#9658;</a> ';
                        #output += ' <a href="?' + (self -> (urlargs: -except=(array: -
page), -suffix='&amp;'))
                                + '-page=' + (self -> lastpage) + '" class="prevnext"'
                                + ' title="Go to last page">&#9658;|</a> ';
                else;
                        #output += ' <span class="prevnext dim">&#9642;&#9642;&#9658;</
span>  <span class="prevnext dim">&#9658;|</span> ';
                /if;
                #output += '</th></tr>';
                (local_defined: 'end') ? #output += '</table>\n';
                return: @#output;
        /define_tag;
       
        define_tag: 'page'; return: (self -> 'page'); /define_tag;
       
        define_tag: 'lastpage';
                if: (self -> 'database') -> 'found_count' > 0;
                        return: (((self -> 'database') -> 'found_count' - 1) / (self ->  
'database') -> 'maxrecords_value') + 1;
                else;
                        return: 1;
                /if;
        /define_tag;
       
        define_tag: 'page_skiprecords',
                -required='maxrecords', -type='integer';
                // converts page value to a skiprecords value to use in search
                return: ((self -> 'page') - 1) * #maxrecords;
        /define_tag;
       

        define_tag: 'trace',
                -optional='html';
                local: 'eol'=(local_defined: 'html') ? '<br>\n' | '\n';

                return: #eol + 'Grid debug trace' + #eol + (self -> 'debug_trace') -
 > (join: #eol) + #eol;

        /define_tag;


/define_type;

?>



#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://lists.montania.se/Lists/knop/
(log in with your email and ConfirmationID as password, send message to
<[hidden email]> to get that ID)
Project homepage http://montania.se/projects/knop/
AIM chatroom knop aim:gochat?roomname=knop


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Language support in knop_grid

Jolle Carlestam-2
Found some more strings. So far I have these:

local:'searchLabel' = 'Search',
        'showLabel' = 'Show all',
        'changeSortOrd' = 'Change sort order to ',
        'sortAsc' = 'ascending',
        'sortDes' = 'descending',
        'sortAscBy' = 'Sort ascending by ',
        'goFirst' = 'Go to first page',
        'goPrev' = 'Go to previous page',
        'goNext' = 'Go to next page',
        'goLast' = 'Go to last page',
        'unsort' = 'Unsort';

Are there more?

HDB
Jolle

8 mar 2007 kl. 22.57 skrev [hidden email]:

> I noticed that knop_grid have hardcoded language strings.  
> Specifically Search and Show all.


#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://lists.montania.se/Lists/knop/
(log in with your email and ConfirmationID as password, send message to
<[hidden email]> to get that ID)
Project homepage http://montania.se/projects/knop/
AIM chatroom knop aim:gochat?roomname=knop


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Language support in knop_grid

Jolle Carlestam-2
In reply to this post by Jolle Carlestam-2
Here's latest version with all strings I could find:

/.../

Scratch that!

Turns out that there's a max limit on mail size on the list so this  
mail got rejected.

Well I got a new version adding language support to the grid if  
anyone's interested.

HDB
Jolle

#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://lists.montania.se/Lists/knop/
(log in with your email and ConfirmationID as password, send message to
<[hidden email]> to get that ID)
Project homepage http://montania.se/projects/knop/
AIM chatroom knop aim:gochat?roomname=knop


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Language support in knop_grid

Johan Solve-2
In reply to this post by Jolle Carlestam-2
At 01.06 +0100 2007-03-09, [hidden email] wrote:
>Turns out that there's a max limit on mail size on the list so this mail got rejected.

I changed the settings now. Up to 1 MB should be ok.
--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:[hidden email]
 (spam-safe email address, replace '-' with 'a')

#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://lists.montania.se/Lists/knop/
(log in with your email and ConfirmationID as password, send message to
<[hidden email]> to get that ID)
Project homepage http://montania.se/projects/knop/
AIM chatroom knop aim:gochat?roomname=knop

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Language support in knop_grid

Jolle Carlestam-2
In reply to this post by Jolle Carlestam-2
9 mar 2007 kl. 08.54 skrev Johan Solve:

>> Turns out that there's a max limit on mail size on the list so  
>> this mail got rejected.
>
> I changed the settings now. Up to 1 MB should be ok.

Great, then here's the code again. It adds an optional param to the  
knop_grid, -language, allowing for language support of hardcoded  
strings. Sofar it supports English and Swedish. Default is English.

Note that I've changed all mt_ to knop_ as suggested by Johan. I've  
done that thru-out all the Knop files.

HDB
Jolle

Here's latest version with all strings I could find:

<?LassoScript

define_type: 'grid',
        -namespace='knop_';
// -prototype;

/*

CHANGE NOTES
2007-03-08 JC Added support for an optional param -Language to handle  
hardcoded strings
2007-03-01 JS Added support for FileMaker with quicksearch (untested)
2007-03-01 JS Changed all texts to English
2007-02-07 JS Removed classs="first" and class="notopborder" since  
CSS border-collapse: collapse; eliminates the need
2007-02-05 JS The -keyvalue parameter for url edit links can be given  
another name by specifying -keyparamname in addfield
2007-01-31 JS ->addfield: #value# can be used in -url, as a way to  
provide mailto links etc in lists
2007-01-30 JS Sortable columns now thave three states instead of two:  
sorted ascending, sorted descending and unsorted.
2007-01-30 JS Improvements to quicksearch, to emulate "word begins  
with"  searches
2007-01-26 JS Added support for quicksearch field in grid header.  
Specify -quicksearch at ->oncreate, and tell what fields to search by  
specifying -quicksearch for those fields at ->addfield.
                                Fields can be search only (no display) by leaving out name and  
label. All specified fields are searched word for word of thew search  
string.
                                Use ->quicksearch to get the search parameters (optionally -sql)
2007-01-26 JS Added ->urlargs to get a querystring with all "-" GET  
params, except those in optional -except string or array parameter.
2007-01-22 JS Adjustments to highlighting and "(redigera)"-link for  
records with empty values in the linked field
2007-01-19 JS Added href titles to sort links and prevnext links
2007-01-19 JS Corrected sortparams when no sortfield is specified
2007-01-19 JS Addded go to first page, go to last page in footer
2007-01-19 JS Added member tag page_skiprecords to help correcting  
out of bounds page numbers
2007-01-19 JS Added member tag lastpage
2007-01-18 JS Support for highlighting of affected record after edit  
or update (class name highlight)
2007-01-17 JS Added addfield: -template

TODO
Make texts in header and footer configurable

*/
        local: 'version'='2007-03-08';
        local: 'build'='2007-03-08 00:44';
        define_tag: 'help';
                return:
'knop_grid, a custom type to handle data grids (record listings).

Version ' + (self -> 'version') + '


-> oncreate
        required: -database type: -database // database object that the grid  
object will interact with
        optional: -nav type: -nav // optional navigation object to  
interact with
        optional: -quicksearch // flag or value, optional quick search  
box, if string is provided then that is used as label text
        optional: -language // value, if used sets hardcoded string  
values to the specified language. Defaults to English
       
-> onassign // needed to restore references when ctype is defined as  
prototype
        required: -value

-> addfield // Adds a column to the record listing
        optional: -name // Name of the field
        optional: -label // Column heading
        optional: -dbfield // corresponding database field name (name is  
used if dbfield is not specified)
        optional: -width // pixels (CSS width)
        optional: -class // CSS class name to use for the column cells
        optional: -url // field will be linked with this url as base. Can  
contain #value# for example to create clickable email links.
        optional: -keyparamname // param name to use instead of the default -
keyvalue for edit links
        optional: -defaultsort // flag, this field will be the default sort  
field
        optional: -nosort // flag, the field header should not be clickable  
for sort
        optional: -template // either string to format values or map  
containing templates to display individual values in different ways,  
use -default to display unknown values, use #value# to insert the  
actual field value in the template
        optional: -quicksearch // flag, if specified, the field will be used  
for search with quicksearch
       
-> sortparams // Returns a Lasso-style pair array with sort  
parameters to use in the search inline.
        optional: -sql // flag, return an SQL string for the sort parameters  
instead.

-> quicksearch // Returns a pair array with fieldname=value
        optional: -sql // flag, return an SQL string for the search  
parameters instead.

-> urlargs // returns all get params that begin with - as a query  
string, for internal use in links in the grid
        optional: -except // exclude these parameters (string or array)
        optional: -prefix // for example ? or &amp; to include at the  
beginning of the querystring
        optional: -suffix // for example &amp; to include at the end of the  
querystring

-> renderhtml // Outputs the complete record listing.
                                // Calls renderheader and renderfooter as well.
                                // If 10 records or more are shown, renderfooter is added also  
just below the header.
        optional: -inlinename // If not specified, inlinename from the  
connected database object is used

-> renderheader // Outputs the header of the grid with the column  
headings.
                                // Automatically included by ->renderhtml
        optional: -start // flag, also output opening <table> tag

-> renderfooter // Outputs the footer of the grid with the prev/next  
links and information about found count
                                // Automatically included by ->renderhtml
        optional: -end // flag, also output closing </table> tag

-> page // Returns the current page number

-> lastpage // Returns the number of the last page for the found  
records

-> page_skiprecords // converts page value to a skiprecords value to  
use in search
        required: -maxrecords type: -integer // Needed to be able to do the  
calculation. Maxrecords_value can not be taken from the database  
object since taht value is not available until aftetr performing the  
search

-> trace // outputs debug information
        optional: -html // formats debug info with <be> linebreaks

';
        /define_tag;

        // instance variables
        local: 'fields'=array,
                'dbfieldmap'=map,
                'sortfield'=string,
                'defaultsort'=string,
                'page'=integer,
                'sortdescending'=false,
                'database'=null,
                'nav'=null,
                'debug_trace'=array,
                'quicksearch'=string,
                'quicksearch_form',
                'quicksearch_form_reset',
                'quicksearch_fields'=array,
                'searchLabel' = string,
                'showLabel' = string,
                'changeSortOrd' = string,
                'sortAsc' = string,
                'sortDes' = string,
                'sortAscBy' = string,
                'goFirst' = string,
                'foundC' = string,
                'goPrev' = string,
                'goNext' = string,
                'goLast' = string,
                'unsort' = string
                ;

               
        define_tag: 'oncreate',
                -required='database', -type='database', // database object that the  
grid object will interact with
                -optional='nav', -type='nav', // optional navigation object to  
interact with
                -optional='quicksearch', // optional quick search box, if string  
is provided then that is used as label text
                -optional='language'; // optional language setting. If not used  
default is English
               
                // the following params are stored as reference, so the values of  
the params can be altered after adding a field simply by changing the  
referenced variable.
                iterate: (array:
                        'database', 'nav'), (local: 'param');
                        (local_defined: #param) ? (self -> #param = @(local: #param));
                /iterate;
               
                local: 'clientparams'=client_getparams;
                #clientparams -> (merge: client_postparams);
                (self -> 'sortfield') = (#clientparams >> -sort ? (#clientparams ->  
(find: -sort) -> first -> value) | string);
                (self -> 'sortdescending') = (#clientparams >> -desc);
                (self -> 'page') = (#clientparams >> -page ? (integer:  
(#clientparams -> (find: -page) -> first -> value)) | 1);
                (self -> 'page') < 1 ? (self -> 'page') = 1;

                if: (local_defined: 'language');
                        select: #language;
                                case:'English';
                                        (self -> 'searchLabel') = 'Searchme';
                                        (self -> 'showLabel') = 'Show all';
                                        (self -> 'changeSortOrd') = 'Change sort order to ';
                                        (self -> 'sortAsc') = 'ascending';
                                        (self -> 'sortDes') = 'descending';
                                        (self -> 'sortAscBy') = 'Sort ascending by ';
                                        (self -> 'goFirst') = 'Go to first page';
                                        (self -> 'foundC') = ' found';
                                        (self -> 'goPrev') = 'Go to previous page';
                                        (self -> 'goNext') = 'Go to next page';
                                        (self -> 'goLast') = 'Go to last page';
                                        (self -> 'unsort') = 'Unsort';
                                case:'Swedish';
                                        (self -> 'searchLabel') = 'Sök';
                                        (self -> 'showLabel') = 'Visa alla';
                                        (self -> 'changeSortOrd') = 'Ändra sorteringsordning till ';
                                        (self -> 'sortAsc') = 'stigande';
                                        (self -> 'sortDes') = 'fallande';
                                        (self -> 'sortAscBy') = 'Sortera stigande på ';
                                        (self -> 'goFirst') = 'Gå till första sidan';
                                        (self -> 'goPrev') = 'Gå till föregående sida';
                                        (self -> 'foundC') = ' funna';
                                        (self -> 'goNext') = 'Gå till nästa sida';
                                        (self -> 'goLast') = 'Gå till sista sidan';
                                        (self -> 'unsort') = 'Ta bort sortering';
                                case;
                                        (self -> 'searchLabel') = 'Searchhim';
                                        (self -> 'showLabel') = 'Show all';
                                        (self -> 'changeSortOrd') = 'Change sort order to ';
                                        (self -> 'sortAsc') = 'ascending';
                                        (self -> 'sortDes') = 'descending';
                                        (self -> 'sortAscBy') = 'Sort ascending by ';
                                        (self -> 'goFirst') = 'Go to first page';
                                        (self -> 'goPrev') = 'Go to previous page';
                                        (self -> 'foundC') = ' found';
                                        (self -> 'goNext') = 'Go to next page';
                                        (self -> 'goLast') = 'Go to last page';
                                        (self -> 'unsort') = 'Unsort';
                        /select;
                else;
                        (self -> 'searchLabel') = 'Searchthem';
                        (self -> 'showLabel') = 'Show all';
                        (self -> 'changeSortOrd') = 'Change sort order to ';
                        (self -> 'sortAsc') = 'ascending';
                        (self -> 'sortDes') = 'descending';
                        (self -> 'sortAscBy') = 'Sort ascending by ';
                        (self -> 'goFirst') = 'Go to first page';
                        (self -> 'goPrev') = 'Go to previous page';
                        (self -> 'foundC') = ' found';
                        (self -> 'goNext') = 'Go to next page';
                        (self -> 'goLast') = 'Go to last page';
                        (self -> 'unsort') = 'Unsort';
                /if;

                if: (local_defined: 'quicksearch');
                        if: #quicksearch != '';
                                (self -> 'quicksearch') = #quicksearch;
                        else;
                                (self -> 'quicksearch') = 'Quicksearch';
                        /if;
                        (self -> 'quicksearch_form') = (knop_form: -name='quicksearch', -
action='./', -method='get', -template='#field#\n', -noautoparams);
                        (self -> 'quicksearch_form_reset') = (knop_form: -
name='quicksearch_reset', -action='./', -method='get', -
template='#field#\n', -noautoparams);
                        local: 'autosavekey'=server_name + response_path;
                        if: (self -> 'nav') -> type =='nav' && (self -> 'nav') ->  
'navmethod'=='param';
                                (self -> 'quicksearch_form') -> (addfield: -type='hidden', -
name='-path', -value=((self -> 'nav') -> path));
                                (self -> 'quicksearch_form_reset') -> (addfield: -type='hidden', -
name='-path', -value=((self -> 'nav') -> path));
                                #autosavekey -> (removetrailing: '/');
                                #autosavekey += '/' + ((self -> 'nav') -> path);
                        /if;
                        if: (self -> 'sortfield') != '';
                                (self -> 'quicksearch_form') -> (addfield: -type='hidden', -
name='-sort', -value=(self -> 'sortfield'));
                                (self -> 'quicksearch_form_reset') -> (addfield: -type='hidden', -
name='-sort', -value=(self -> 'sortfield'));
                                if: (self -> 'sortdescending');
                                        (self -> 'quicksearch_form') -> (addfield: -type='hidden', -
name='-desc');
                                        (self -> 'quicksearch_form_reset') -> (addfield: -type='hidden',  
-name='-desc');
                                /if;
                        /if;
                        (self -> 'quicksearch_form') -> (addfield: -type='search', -name='-
q', -hint=(self -> 'quicksearch'),
                                -size=15, -id='quicksearch_q', -raw='autosave="' + #autosavekey +  
'" results="10"');
                        (self -> 'quicksearch_form') -> (addfield: -type='submit', -
name='s', -value= (self -> 'searchLabel'));
                        if: #clientparams >> -q;
                                (self -> 'quicksearch_form') -> (setvalue: '-q'=(#clientparams ->  
(find: -q) -> first -> value));
                                (self -> 'quicksearch_form_reset') -> (addfield: -type='submit', -
name='a', -value= (self -> 'showLabel'));
                        else;
                                (self -> 'quicksearch_form_reset') -> (addfield: -type='submit', -
name='a', -value= (self -> 'showLabel'), -disabled);
                        /if;
                /if;
        /define_tag;

        define_tag: 'onassign', -required='value'; // needed to restore  
references when ctype is defined as prototype
                // recreate references here
                (self->'database') = @(#value -> 'database');
                (self->'nav') = @(#value -> 'nav');
        /define_tag;

        define_tag: 'onconvert';
        /define_tag;
       
        define_tag: '_unknowntag';
                return: 'Member tag -> ' + Tag_name + ' not known';
        /define_tag;
       
       
        define_tag: 'addfield',
                -optional='name',
                -optional='label',
                -optional='dbfield', // corresponding database field name (name is  
used if dbfield is not specified)
                -optional='width', // pixels (css width)
                -optional='class',
                -optional='url', // field will be linked with this url as base
                -optional='keyparamname',// param name to use instead of the  
default -keyvalue for edit links
                -optional='defaultsort', // this field will be the default sort field
                -optional='nosort', // the field header should not be clickable  
for sort
                -optional='template', // either string to format values or map  
containing templates to display individual values in different ways,  
use -default to display unknown values, use #value# to insert the  
actual field value in the template
                -optional='quicksearch'; // if specified, the field will be used  
for search with quicksearch
               
                fail_if: (local_defined: 'template') && #template -> type !=  
'string' && #template -> type != 'map', -1, 'Template must be either  
string or map';
                local: 'field'=map;
                iterate: (array: 'name', 'class', 'url', 'keyparamname', 'width'),  
(local: 'param');
                        (local_defined: #param) ? (#field -> (insert: #param = (local:  
#param)));
                /iterate;
                #field !>> 'keyparamname' ? #field -> (insert: 'keyparamname' = -
keyvalue);
               
                if: (local_defined: 'template');
                        #field -> (insert: 'template'=(#template -> type == 'string' ?  
(map: -default=#template) | #template));
                /if;
                if: (local_defined: 'name');
                        #field -> (insert: 'label'=( (local_defined: 'label') ? #label |  
#name ) );
                        #field -> (insert: 'dbfield'=( (local_defined: 'dbfield') ?  
#dbfield | #name ) );
                        #field -> (insert: 'nosort'=(local_defined: 'nosort'));
                        if: local_defined: 'defaultsort' && !(local_defined: 'nosort') &&  
(self -> 'defaultsort') == '';
                                (self -> 'defaultsort') = #name;
                                if: (self -> 'sortfield') == '';
                                        (self -> 'sortfield') = (self -> 'defaultsort');
                                /if;
                        /if;
                        (self -> 'dbfieldmap') -> (insert: #name = ((local_defined:  
'dbfield') ? #dbfield | #name));
                /if;
                (local_defined: 'quicksearch') ? (self -> 'quicksearch_fields') ->  
(insert: ((local_defined: 'dbfield') ? #dbfield | (local: 'name')));
               
                if: local_defined: 'name' || local_defined: 'label';
                        (self -> 'fields') -> (insert: #field);
                /if;
        /define_tag;
       
        define_tag: 'sortparams',
                -optional='sql';
                        if: local_defined: 'sql';
                                fail_if: (self -> 'database') -> 'isfilemaker', 7009, '-sql can  
not be used with FileMaker';
                                (self -> 'sortfield') == '' ? return;
                                local: 'output'=' ORDER BY ';
                                if: (self -> 'dbfieldmap') >> (self -> 'sortfield');
                                        #output += ((self -> 'dbfieldmap') -> (find: (self ->  
'sortfield')));
                                else;
                                        #output += (self -> 'sortfield');
                                /if;
                                if: (self -> 'sortdescending');
                                        #output += ' DESC';
                                /if;
                        else;
                                local: 'output'=array;
                                (self -> 'sortfield') == '' ? return: @#output;
                                if: (self -> 'dbfieldmap') >> (self -> 'sortfield');
                                        #output -> (insert: -sortfield=(self -> 'dbfieldmap') -> (find:  
(self -> 'sortfield')) );
                                else;
                                        #output -> (insert: -sortfield=(self -> 'sortfield'));
                                /if;
                                if: (self -> 'sortdescending');
                                        #output -> (insert: -sortorder='descending');
                                /if;
                        /if;
                return: @#output;
        /define_tag;

        define_tag: 'quicksearch',
                -optional='sql';
                // Returns a pair array with fieldname=value, or optionally SQL  
string to be used in an update inline.
                local: 'output'=array,
                        'output_temp'=array,
                        '_sql'=(local_defined: 'sql'),
                        'wordseparators'=',.- ("',
                        'fieldvalue', 'onevalue', 'field', 'wordseparator';
                fail_if: #_sql && (self -> 'database') -> 'isfilemaker', 7009, '-
sql can not be used with FileMaker';

                #wordseparators = #wordseparators -> (split: '');
                if: (self -> 'quicksearch_form') -> type != 'form';
                        if: #_sql;
                                return: string;
                        else;
                                return: array;
                        /if;
                /if;
                #fieldvalue = string: ((self -> 'quicksearch_form') -> (getvalue: '-
q'));
                if: #fieldvalue != '';
                        if: (self -> 'database') -> 'isfilemaker';
                                #output -> (insert: -logicaloperator='or');
                                iterate: (self -> 'quicksearch_fields'), #field;
                                        #output -> (insert:  #field = #fieldvalue);
                                /iterate;
                        else;
                                // search each word separately
                                #fieldvalue = #fieldvalue -> (split: ' ');
                                iterate: #fieldvalue, #onevalue;
                                        #output_temp = array;
                                        iterate: (self -> 'quicksearch_fields'), #field;
                                                if: #_sql;
                                                        #output_temp -> (insert:  (encode_sql: #field )
                                                                + ' LIKE "' + (encode_sql: #onevalue ) + '%"');
                                                        // basic emulation of "word begins with"
                                                        iterate: #wordseparators, #wordseparator;
                                                                #output_temp -> (insert:  (encode_sql: #field )
                                                                        + ' LIKE "%' + (encode_sql: #wordseparator + #onevalue ) +  
'%"');
                                                        /iterate;
                                                else;
                                                        #output_temp -> (insert:  -op='bw');
                                                        #output_temp -> (insert:  #field = #onevalue );
                                                        if: !(self -> 'database' -> 'isfilemaker');
                                                                // this variant is not needed for FileMaker since it already  
searches with "word begins with" as default #output_temp ->  
(insert:  -op='cn');
                                                                iterate: #wordseparators, #wordseparator;
                                                                        #output_temp -> (insert:  -op='cn');
                                                                        #output_temp -> (insert:  #field = #wordseparator +  
#onevalue );
                                                                /iterate;
                                                        /if;
                                                /if;
                                        /iterate;
                                        if: #_sql;
                                                if: #output_temp -> size > 1;
                                                        #output_temp = '(' + #output_temp -> (join: ' OR ') + ')';
                                                else;
                                                        #output_temp = #output_temp -> first;
                                                /if;
                                                #output -> (insert: #output_temp);
                                        else;
                                                if: #output_temp -> size > 2;
                                                        #output_temp -> (insert: -opbegin='or', 1);
                                                        #output_temp -> (insert: -opend='or');
                                                /if;
                                                #output -> (merge: #output_temp);
                                        /if;
                                /iterate;
                               
                                if: #_sql;
                                        if: #output -> size;
                                                #output = '(' + #output -> (join: ' AND ') + ')';
                                        else;
                                                #output = string;
                                        /if;
                                else;
                                        if: #output -> size;
                                                #output -> (insert: -opbegin='and', 1);
                                                #output -> (insert: -opend='and');
                                        /if;
                                /if;
                        /if; // isfilemaker
                /if; // #fieldvalue != ''
                return: @#output;
        /define_tag;
       
        define_tag: 'urlargs', // returns all get params that begin with -  
as a query string
                -optional='except', -copy,
                -optional='prefix', // for example ? or &amp; to include at the  
beginning of the querystring
                -optional='suffix'; // for example &amp; to include at the end of  
the querystring
                local: 'output'=array, 'param';
                local: 'clientparams'=client_getparams;

                !(local_defined: 'except') ? local: 'except'=array;
                #except -> type != 'array' ? #except = array: #except;
               
                iterate: #clientparams, #param;
                        if: #param -> type == 'pair';
                                if: #param -> name -> (beginswith: '-') && #except !>> #param ->  
name;
                                        #output -> (insert: (#param -> name) + '=' + (#param -> value));
                                /if;
                        else; // just a string param (no pair)
                                if: #param -> (beginswith: '-') && #except !>> #param;
                                        #output -> (insert: #param);
                                /if;
                        /if;
                /iterate;
                if: #output -> size;
                        return: (local: 'prefix') + (#output -> (join: '&amp;')) + (local:  
'suffix');
                /if;

        /define_tag;
       
       
        define_tag: 'renderhtml',
                -optional='inlinename';
                local: '_inlinename'=string,
                        'output'=string,
                        'fields'=(self -> 'fields'),
                        'field'=string,
                        'keyfield'=null,
                        'affectedrecord_keyvalue'=null,
                        'record_loop_count'=integer,
                        'db'=@(self -> 'database'),
                        'nav'=@(self -> 'nav'),
                        'dbfieldmap'=@(self -> 'dbfieldmap'),
                        'classarray'=array,
                        'fieldname'=string,
                        'value'=string,
                        'keyparamname',
                        'url';
                if: (local: 'inlinename')!='';
                        #_inlinename = #inlinename;
                else: #db -> type == 'database';
                        #_inlinename=#db -> 'inlinename';
                        #keyfield=#db -> 'keyfield';
                        #affectedrecord_keyvalue = #db -> 'affectedrecord_keyvalue';
                /if;
                #output += (self -> (renderheader: -start));
                if: #db -> shown_count >= 10;
                        #output += (self -> renderfooter);
                /if;
                #output += '<tbody>';
                records: -inlinename=#_inlinename;
                        #record_loop_count = loop_count;
                        #output += '\n<tr>';
                        iterate: #fields, #field;
                                #fieldname = (#dbfieldmap -> (find: (#field -> (find: 'name'))));
                                #keyparamname = (#field -> (find: 'keyparamname'));
                                #value=(field: #fieldname);
                                if: #field -> (find: 'template') -> type == 'map';
                                        if: #field -> (find: 'template') >> #value;
                                                #value = #field -> (find: 'template') -> (find: #value);
                                        else: #field -> (find: 'template') >> -default;
                                                #value = #field -> (find: 'template') -> (find: -default);
                                        else;
                                                // show fieldvalue as is
                                        /if;
                                        // substitute field value in the display template
                                        #value -> (replace: '#value#', (field: #fieldname));
                                /if;
                                #classarray=array;
                                if:  #affectedrecord_keyvalue == (field: #keyfield) && (field:  
#keyfield) != '';
                                        // hightlight affected row
                                        #classarray -> (insert: 'highlight');
                                else;
                                        (#record_loop_count - 1)  % 2 == 0 ? #classarray -> (insert:  
'even');
                                /if;
                                #output += '<td';
                                if: #classarray -> size;
                                        #output += ' class="' + #classarray -> (join: ' ') + '"';
                                /if;
                                #output += '>';
                                if: (#field -> (find: 'url')) != '';
                                        #url = (#field -> (find: 'url'));
                                        if: #nav -> type == 'nav' && #url !>> '#value#';
                                                #output += '<a href="' + (#nav -> (url: -path=#url,
                                                        #keyparamname=(field: #keyfield),
                                                        -urlargs=(self -> (urlargs: -except=(array: -path,  
#keyparamname)))));
                                                #output += '">' +  #value
                                                        // show something to click on even if the field is empty
                                                        + ((string_findregexp: #value, -find='\\w*') -> size == 0 ?  
'(edit)')
                                                        + '</a>';
                                        else;
                                                #url -> (replace: '#value#', (field: #fieldname));
                                                #output += '<a href="' + #url + '"';
                                                #url -> (beginswith: 'http://') || #url -> (beginswith:  
'https://') || #url -> (beginswith: 'mailto:')
                                                        ? #output += ' class="ext"';
                                                #output += '>' +  #value + '</a>';
                                        /if;
                                else;
                                        #output += #value;
                                /if;
                                #output += '</td>\n';
                        /iterate;
                        #output += '</tr>\n';
                /records;
                #output += '</tbody>\n';
                #output += (self -> (renderfooter: -end));
        return: @#output;
        /define_tag;
       
        define_tag: 'renderheader',
                -optional='start';
                local: 'output'=string,
                        'db'=@(self -> 'database'),
                        'nav'=@(self -> 'nav'),
                        'fields'=@(self -> 'fields'),
                        'field'=string,
                        'classarray'=array;
                (local_defined: 'start') ? #output += '<table>';
                #output += '<thead>\n<tr>';
                if: (self -> 'quicksearch_form') -> type == 'form';
                        #output += '<th colspan="' + (#fields -> size) + '"  
class="quicksearch';
                                ((self -> 'quicksearch_form') -> (getvalue: '-q') != '') ?  
#output += ' highlight';
                        #output += '">';
                        #output += (self -> 'quicksearch_form') -> renderform;
                        if: (self -> 'quicksearch_form_reset') -> type =='form';
                                #output += (self -> 'quicksearch_form_reset') -> renderform;
                        /if;
                        #output += '</th></tr>\n<tr>';
                /if;
                iterate: #fields, #field;
                        #classarray=array;
                        //(self -> 'quicksearch_form') -> type == 'form' ? #classarray ->  
(insert: 'notopborder');
                        (self -> 'sortfield') == (#field -> (find: 'name')) && !(#field ->  
(find: 'nosort')) ? #classarray -> (insert: 'sort');
                        #output += '<th';
                        if: #field -> (find: 'width') > 0;
                                #output += ' style="width: ' + (integer: #field -> (find:  
'width')) + 'px;"';
                        /if;
                        if: #classarray -> size;
                                #output += ' class="' + #classarray -> (join: ' ') + '"';
                        /if;
                        #output += '>';
                        if: (#field -> (find: 'nosort'));
                                #output += '<div>' + (#field -> (find: 'label')) '</div>';
                        else;
                                if: (#classarray >> 'sort' && (self -> 'sortdescending'));
                                        // create link to change to unsorted
                                        #output += '<a href="./'
                                                + (self -> (urlargs: -except=(array: -sort, -desc, -page), -
prefix='?')) + '"'
                                                + ' title="' + #Unsort + '">';
                                else;
                                        // create link to toggle sort mode
                                        #output += '<a href="./?-sort=' + (#field -> (find: 'name'))
                                                + (#classarray >> 'sort' && !(self -> 'sortdescending') ?  
'&amp;-desc')
                                                + (self -> (urlargs: -except=(array: -sort, -desc, -page), -
prefix='&amp;')) + '"'
                                                + ' title="' + (#classarray >> 'sort'
                                                        ? (self -> 'changeSortOrd')
                                                                + ((self -> 'sortdescending') ? (self -> 'sortAsc') | (self -
 > 'sortDes'))
                                                        | (self -> 'sortAscBy') + (encode_html: (#field -> (find:  
'label'))) ) + '">';
                                /if;
                                #output += (#field -> (find: 'label'));
                                if: (string_findregexp: (#field -> (find: 'label')), -find='\\S')  
-> size == 0;
                                        #output += '&nbsp;'; // to show sort link as block element  
properly even for empty label
                                /if;
                                if: #classarray >> 'sort';
                                        #output += ' <span class="sortmarker"> ' + ((self ->  
'sortdescending') ? '&#9660;' | '&#9650;') + '</span>';
                                /if;
                                #output += '</a>';
                         /if;
                         #output += '</th>\n';
                /iterate;
                #output += '</tr></thead>\n';
                return: @#output;
        /define_tag;

        define_tag: 'renderfooter',
                -optional='end';
                // unicode symbols http://www.alanwood.net/unicode/ 
geometric_shapes.html
                local: 'output'=string,
                        'db'=@(self -> 'database'),
                        'nav'=@(self -> 'nav'),
                        'fields'=@(self -> 'fields'),
                        'field'=string;
                #output += '<tr><th colspan="' + (#fields -> size) + '"  
class="footer first' + (!(local_defined: 'end') &&false? '  
notopborder') + '">';
               
                if: (self -> 'page') > 1;
                        #output += ' <a href="?' + (self -> (urlargs: -except=(array: -
page), -suffix='&amp;'))
                                + '-page=1" class="prevnext"'
                                + ' title="' + (self -> 'goFirst') + '">|&#9668;</a> ';

                        #output += ' <a href="?' + (self -> (urlargs: -except=(array: -
page), -suffix='&amp;'))
                                + '-page=' + ((self -> 'page') - 1)
                                + '" class="prevnext"'
                                + ' title="' + (self -> 'goPrev') + '">&#9668;&#9642;&#9642;</a> ';
                else;
                        #output += ' <span class="prevnext dim">|&#9668;</span> <span  
class="prevnext dim">&#9668;&#9642;&#9642;</span> ';
                /if;
                if: #db -> found_count > #db -> shown_count;
                        #output += #db -> shown_first + ' - ' #db -> shown_last + ' of ';
                /if;
                #output += #db -> found_count + (self -> 'foundC');
                if: (#db -> shown_last) < (#db -> found_count);
                        #output += ' <a href="?' + (self -> (urlargs: -except=(array: -
page), -suffix='&amp;'))
                                + '-page=' + ((self -> 'page') + 1) + '" class="prevnext"'
                                + ' title="' + (self -> 'goNext') + '">&#9642;&#9642;&#9658;</a> ';
                        #output += ' <a href="?' + (self -> (urlargs: -except=(array: -
page), -suffix='&amp;'))
                                + '-page=' + (self -> lastpage) + '" class="prevnext"'
                                + ' title="' + (self -> 'goLast') + '">&#9658;|</a> ';
                else;
                        #output += ' <span class="prevnext dim">&#9642;&#9642;&#9658;</
span>  <span class="prevnext dim">&#9658;|</span> ';
                /if;
                #output += '</th></tr>';
                (local_defined: 'end') ? #output += '</table>\n';
                return: @#output;
        /define_tag;
       
        define_tag: 'page'; return: (self -> 'page'); /define_tag;
       
        define_tag: 'lastpage';
                if: (self -> 'database') -> 'found_count' > 0;
                        return: (((self -> 'database') -> 'found_count' - 1) / (self ->  
'database') -> 'maxrecords_value') + 1;
                else;
                        return: 1;
                /if;
        /define_tag;
       
        define_tag: 'page_skiprecords',
                -required='maxrecords', -type='integer';
                // converts page value to a skiprecords value to use in search
                return: ((self -> 'page') - 1) * #maxrecords;
        /define_tag;
       

        define_tag: 'trace',
                -optional='html';
                local: 'eol'=(local_defined: 'html') ? '<br>\n' | '\n';

                return: #eol + 'Grid debug trace' + #eol + (self -> 'debug_trace') -
 > (join: #eol) + #eol;

        /define_tag;


/define_type;

?>
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://lists.montania.se/Lists/knop/
(log in with your email and ConfirmationID as password, send message to
<[hidden email]> to get that ID)
Project homepage http://montania.se/projects/knop/
AIM chatroom knop aim:gochat?roomname=knop


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Language support in knop_grid

Johan Solve-2
In reply to this post by Jolle Carlestam-2
Thanks, wil merge it in.


At 09.07 +0100 2007-03-09, [hidden email] wrote:

>9 mar 2007 kl. 08.54 skrev Johan Solve:
>
>>>Turns out that there's a max limit on mail size on the list so this mail got rejected.
>>
>>I changed the settings now. Up to 1 MB should be ok.
>
>Great, then here's the code again. It adds an optional param to the knop_grid, -language, allowing for language support of hardcoded strings. Sofar it supports English and Swedish. Default is English.
>
>Note that I've changed all mt_ to knop_ as suggested by Johan. I've done that thru-out all the Knop files.
>
>HDB
>Jolle
>
>Here's latest version with all strings I could find:
>
><?LassoScript
>
>define_type: 'grid',
> -namespace='knop_';
>// -prototype;
>
>/*
>
>CHANGE NOTES
>2007-03-08 JC Added support for an optional param -Language to handle hardcoded strings
>2007-03-01 JS Added support for FileMaker with quicksearch (untested)
>2007-03-01 JS Changed all texts to English
>2007-02-07 JS Removed classs="first" and class="notopborder" since CSS border-collapse: collapse; eliminates the need
>2007-02-05 JS The -keyvalue parameter for url edit links can be given another name by specifying -keyparamname in addfield
>2007-01-31 JS ->addfield: #value# can be used in -url, as a way to provide mailto links etc in lists
>2007-01-30 JS Sortable columns now thave three states instead of two: sorted ascending, sorted descending and unsorted.
>2007-01-30 JS Improvements to quicksearch, to emulate "word begins with"  searches
>2007-01-26 JS Added support for quicksearch field in grid header. Specify -quicksearch at ->oncreate, and tell what fields to search by specifying -quicksearch for those fields at ->addfield.
> Fields can be search only (no display) by leaving out name and label. All specified fields are searched word for word of thew search string.
> Use ->quicksearch to get the search parameters (optionally -sql)
>2007-01-26 JS Added ->urlargs to get a querystring with all "-" GET params, except those in optional -except string or array parameter.
>2007-01-22 JS Adjustments to highlighting and "(redigera)"-link for records with empty values in the linked field
>2007-01-19 JS Added href titles to sort links and prevnext links
>2007-01-19 JS Corrected sortparams when no sortfield is specified
>2007-01-19 JS Addded go to first page, go to last page in footer
>2007-01-19 JS Added member tag page_skiprecords to help correcting out of bounds page numbers
>2007-01-19 JS Added member tag lastpage
>2007-01-18 JS Support for highlighting of affected record after edit or update (class name highlight)
>2007-01-17 JS Added addfield: -template
>
>TODO
>Make texts in header and footer configurable
>
>*/
> local: 'version'='2007-03-08';
> local: 'build'='2007-03-08 00:44';
> define_tag: 'help';
> return:
>'knop_grid, a custom type to handle data grids (record listings).
>
>Version ' + (self -> 'version') + '
>
>
>-> oncreate
> required: -database type: -database // database object that the grid object will interact with
> optional: -nav type: -nav // optional navigation object to interact with
> optional: -quicksearch // flag or value, optional quick search box, if string is provided then that is used as label text
> optional: -language // value, if used sets hardcoded string values to the specified language. Defaults to English
>
>-> onassign // needed to restore references when ctype is defined as prototype
> required: -value
>
>-> addfield // Adds a column to the record listing
> optional: -name // Name of the field
> optional: -label // Column heading
> optional: -dbfield // corresponding database field name (name is used if dbfield is not specified)
> optional: -width // pixels (CSS width)
> optional: -class // CSS class name to use for the column cells
> optional: -url // field will be linked with this url as base. Can contain #value# for example to create clickable email links.
> optional: -keyparamname // param name to use instead of the default -keyvalue for edit links
> optional: -defaultsort // flag, this field will be the default sort field
> optional: -nosort // flag, the field header should not be clickable for sort
> optional: -template // either string to format values or map containing templates to display individual values in different ways, use -default to display unknown values, use #value# to insert the actual field value in the template
> optional: -quicksearch // flag, if specified, the field will be used for search with quicksearch
>
>-> sortparams // Returns a Lasso-style pair array with sort parameters to use in the search inline.
> optional: -sql // flag, return an SQL string for the sort parameters instead.
>
>-> quicksearch // Returns a pair array with fieldname=value
> optional: -sql // flag, return an SQL string for the search parameters instead.
>
>-> urlargs // returns all get params that begin with - as a query string, for internal use in links in the grid
> optional: -except // exclude these parameters (string or array)
> optional: -prefix // for example ? or &amp; to include at the beginning of the querystring
> optional: -suffix // for example &amp; to include at the end of the querystring
>
>-> renderhtml // Outputs the complete record listing.
> // Calls renderheader and renderfooter as well.
> // If 10 records or more are shown, renderfooter is added also just below the header.
> optional: -inlinename // If not specified, inlinename from the connected database object is used
>
>-> renderheader // Outputs the header of the grid with the column headings.
> // Automatically included by ->renderhtml
> optional: -start // flag, also output opening <table> tag
>
>-> renderfooter // Outputs the footer of the grid with the prev/next links and information about found count
> // Automatically included by ->renderhtml
> optional: -end // flag, also output closing </table> tag
>
>-> page // Returns the current page number
>
>-> lastpage // Returns the number of the last page for the found records
>
>-> page_skiprecords // converts page value to a skiprecords value to use in search
> required: -maxrecords type: -integer // Needed to be able to do the calculation. Maxrecords_value can not be taken from the database object since taht value is not available until aftetr performing the search
>
>-> trace // outputs debug information
> optional: -html // formats debug info with <be> linebreaks
>
>';
> /define_tag;
>
> // instance variables
> local: 'fields'=array,
> 'dbfieldmap'=map,
> 'sortfield'=string,
> 'defaultsort'=string,
> 'page'=integer,
> 'sortdescending'=false,
> 'database'=null,
> 'nav'=null,
> 'debug_trace'=array,
> 'quicksearch'=string,
> 'quicksearch_form',
> 'quicksearch_form_reset',
> 'quicksearch_fields'=array,
> 'searchLabel' = string,
> 'showLabel' = string,
> 'changeSortOrd' = string,
> 'sortAsc' = string,
> 'sortDes' = string,
> 'sortAscBy' = string,
> 'goFirst' = string,
> 'foundC' = string,
> 'goPrev' = string,
> 'goNext' = string,
> 'goLast' = string,
> 'unsort' = string
> ;
>
>
> define_tag: 'oncreate',
> -required='database', -type='database', // database object that the grid object will interact with
> -optional='nav', -type='nav', // optional navigation object to interact with
> -optional='quicksearch', // optional quick search box, if string is provided then that is used as label text
> -optional='language'; // optional language setting. If not used default is English
>
> // the following params are stored as reference, so the values of the params can be altered after adding a field simply by changing the referenced variable.
> iterate: (array:
> 'database', 'nav'), (local: 'param');
> (local_defined: #param) ? (self -> #param = @(local: #param));
> /iterate;
>
> local: 'clientparams'=client_getparams;
> #clientparams -> (merge: client_postparams);
> (self -> 'sortfield') = (#clientparams >> -sort ? (#clientparams -> (find: -sort) -> first -> value) | string);
> (self -> 'sortdescending') = (#clientparams >> -desc);
> (self -> 'page') = (#clientparams >> -page ? (integer: (#clientparams -> (find: -page) -> first -> value)) | 1);
> (self -> 'page') < 1 ? (self -> 'page') = 1;
>
> if: (local_defined: 'language');
> select: #language;
> case:'English';
> (self -> 'searchLabel') = 'Searchme';
> (self -> 'showLabel') = 'Show all';
> (self -> 'changeSortOrd') = 'Change sort order to ';
> (self -> 'sortAsc') = 'ascending';
> (self -> 'sortDes') = 'descending';
> (self -> 'sortAscBy') = 'Sort ascending by ';
> (self -> 'goFirst') = 'Go to first page';
> (self -> 'foundC') = ' found';
> (self -> 'goPrev') = 'Go to previous page';
> (self -> 'goNext') = 'Go to next page';
> (self -> 'goLast') = 'Go to last page';
> (self -> 'unsort') = 'Unsort';
> case:'Swedish';
> (self -> 'searchLabel') = 'Sök';
> (self -> 'showLabel') = 'Visa alla';
> (self -> 'changeSortOrd') = 'Ändra sorteringsordning till ';
> (self -> 'sortAsc') = 'stigande';
> (self -> 'sortDes') = 'fallande';
> (self -> 'sortAscBy') = 'Sortera stigande på ';
> (self -> 'goFirst') = 'Gå till första sidan';
> (self -> 'goPrev') = 'Gå till föregående sida';
> (self -> 'foundC') = ' funna';
> (self -> 'goNext') = 'Gå till nästa sida';
> (self -> 'goLast') = 'Gå till sista sidan';
> (self -> 'unsort') = 'Ta bort sortering';
> case;
> (self -> 'searchLabel') = 'Searchhim';
> (self -> 'showLabel') = 'Show all';
> (self -> 'changeSortOrd') = 'Change sort order to ';
> (self -> 'sortAsc') = 'ascending';
> (self -> 'sortDes') = 'descending';
> (self -> 'sortAscBy') = 'Sort ascending by ';
> (self -> 'goFirst') = 'Go to first page';
> (self -> 'goPrev') = 'Go to previous page';
> (self -> 'foundC') = ' found';
> (self -> 'goNext') = 'Go to next page';
> (self -> 'goLast') = 'Go to last page';
> (self -> 'unsort') = 'Unsort';
> /select;
> else;
> (self -> 'searchLabel') = 'Searchthem';
> (self -> 'showLabel') = 'Show all';
> (self -> 'changeSortOrd') = 'Change sort order to ';
> (self -> 'sortAsc') = 'ascending';
> (self -> 'sortDes') = 'descending';
> (self -> 'sortAscBy') = 'Sort ascending by ';
> (self -> 'goFirst') = 'Go to first page';
> (self -> 'goPrev') = 'Go to previous page';
> (self -> 'foundC') = ' found';
> (self -> 'goNext') = 'Go to next page';
> (self -> 'goLast') = 'Go to last page';
> (self -> 'unsort') = 'Unsort';
> /if;
>
> if: (local_defined: 'quicksearch');
> if: #quicksearch != '';
> (self -> 'quicksearch') = #quicksearch;
> else;
> (self -> 'quicksearch') = 'Quicksearch';
> /if;
> (self -> 'quicksearch_form') = (knop_form: -name='quicksearch', -action='./', -method='get', -template='#field#\n', -noautoparams);
> (self -> 'quicksearch_form_reset') = (knop_form: -name='quicksearch_reset', -action='./', -method='get', -template='#field#\n', -noautoparams);
> local: 'autosavekey'=server_name + response_path;
> if: (self -> 'nav') -> type =='nav' && (self -> 'nav') -> 'navmethod'=='param';
> (self -> 'quicksearch_form') -> (addfield: -type='hidden', -name='-path', -value=((self -> 'nav') -> path));
> (self -> 'quicksearch_form_reset') -> (addfield: -type='hidden', -name='-path', -value=((self -> 'nav') -> path));
> #autosavekey -> (removetrailing: '/');
> #autosavekey += '/' + ((self -> 'nav') -> path);
> /if;
> if: (self -> 'sortfield') != '';
> (self -> 'quicksearch_form') -> (addfield: -type='hidden', -name='-sort', -value=(self -> 'sortfield'));
> (self -> 'quicksearch_form_reset') -> (addfield: -type='hidden', -name='-sort', -value=(self -> 'sortfield'));
> if: (self -> 'sortdescending');
> (self -> 'quicksearch_form') -> (addfield: -type='hidden', -name='-desc');
> (self -> 'quicksearch_form_reset') -> (addfield: -type='hidden', -name='-desc');
> /if;
> /if;
> (self -> 'quicksearch_form') -> (addfield: -type='search', -name='-q', -hint=(self -> 'quicksearch'),
> -size=15, -id='quicksearch_q', -raw='autosave="' + #autosavekey + '" results="10"');
> (self -> 'quicksearch_form') -> (addfield: -type='submit', -name='s', -value= (self -> 'searchLabel'));
> if: #clientparams >> -q;
> (self -> 'quicksearch_form') -> (setvalue: '-q'=(#clientparams -> (find: -q) -> first -> value));
> (self -> 'quicksearch_form_reset') -> (addfield: -type='submit', -name='a', -value= (self -> 'showLabel'));
> else;
> (self -> 'quicksearch_form_reset') -> (addfield: -type='submit', -name='a', -value= (self -> 'showLabel'), -disabled);
> /if;
> /if;
> /define_tag;
>
> define_tag: 'onassign', -required='value'; // needed to restore references when ctype is defined as prototype
> // recreate references here
> (self->'database') = @(#value -> 'database');
> (self->'nav') = @(#value -> 'nav');
> /define_tag;
>
> define_tag: 'onconvert';
> /define_tag;
>
> define_tag: '_unknowntag';
> return: 'Member tag -> ' + Tag_name + ' not known';
> /define_tag;
>
>
> define_tag: 'addfield',
> -optional='name',
> -optional='label',
> -optional='dbfield', // corresponding database field name (name is used if dbfield is not specified)
> -optional='width', // pixels (css width)
> -optional='class',
> -optional='url', // field will be linked with this url as base
> -optional='keyparamname',// param name to use instead of the default -keyvalue for edit links
> -optional='defaultsort', // this field will be the default sort field
> -optional='nosort', // the field header should not be clickable for sort
> -optional='template', // either string to format values or map containing templates to display individual values in different ways, use -default to display unknown values, use #value# to insert the actual field value in the template
> -optional='quicksearch'; // if specified, the field will be used for search with quicksearch
>
> fail_if: (local_defined: 'template') && #template -> type != 'string' && #template -> type != 'map', -1, 'Template must be either string or map';
> local: 'field'=map;
> iterate: (array: 'name', 'class', 'url', 'keyparamname', 'width'), (local: 'param');
> (local_defined: #param) ? (#field -> (insert: #param = (local: #param)));
> /iterate;
> #field !>> 'keyparamname' ? #field -> (insert: 'keyparamname' = -keyvalue);
>
> if: (local_defined: 'template');
> #field -> (insert: 'template'=(#template -> type == 'string' ? (map: -default=#template) | #template));
> /if;
> if: (local_defined: 'name');
> #field -> (insert: 'label'=( (local_defined: 'label') ? #label | #name ) );
> #field -> (insert: 'dbfield'=( (local_defined: 'dbfield') ? #dbfield | #name ) );
> #field -> (insert: 'nosort'=(local_defined: 'nosort'));
> if: local_defined: 'defaultsort' && !(local_defined: 'nosort') && (self -> 'defaultsort') == '';
> (self -> 'defaultsort') = #name;
> if: (self -> 'sortfield') == '';
> (self -> 'sortfield') = (self -> 'defaultsort');
> /if;
> /if;
> (self -> 'dbfieldmap') -> (insert: #name = ((local_defined: 'dbfield') ? #dbfield | #name));
> /if;
> (local_defined: 'quicksearch') ? (self -> 'quicksearch_fields') -> (insert: ((local_defined: 'dbfield') ? #dbfield | (local: 'name')));
>
> if: local_defined: 'name' || local_defined: 'label';
> (self -> 'fields') -> (insert: #field);
> /if;
> /define_tag;
>
> define_tag: 'sortparams',
> -optional='sql';
> if: local_defined: 'sql';
> fail_if: (self -> 'database') -> 'isfilemaker', 7009, '-sql can not be used with FileMaker';
> (self -> 'sortfield') == '' ? return;
> local: 'output'=' ORDER BY ';
> if: (self -> 'dbfieldmap') >> (self -> 'sortfield');
> #output += ((self -> 'dbfieldmap') -> (find: (self -> 'sortfield')));
> else;
> #output += (self -> 'sortfield');
> /if;
> if: (self -> 'sortdescending');
> #output += ' DESC';
> /if;
> else;
> local: 'output'=array;
> (self -> 'sortfield') == '' ? return: @#output;
> if: (self -> 'dbfieldmap') >> (self -> 'sortfield');
> #output -> (insert: -sortfield=(self -> 'dbfieldmap') -> (find: (self -> 'sortfield')) );
> else;
> #output -> (insert: -sortfield=(self -> 'sortfield'));
> /if;
> if: (self -> 'sortdescending');
> #output -> (insert: -sortorder='descending');
> /if;
> /if;
> return: @#output;
> /define_tag;
>
> define_tag: 'quicksearch',
> -optional='sql';
> // Returns a pair array with fieldname=value, or optionally SQL string to be used in an update inline.
> local: 'output'=array,
> 'output_temp'=array,
> '_sql'=(local_defined: 'sql'),
> 'wordseparators'=',.- ("',
> 'fieldvalue', 'onevalue', 'field', 'wordseparator';
> fail_if: #_sql && (self -> 'database') -> 'isfilemaker', 7009, '-sql can not be used with FileMaker';
>
> #wordseparators = #wordseparators -> (split: '');
> if: (self -> 'quicksearch_form') -> type != 'form';
> if: #_sql;
> return: string;
> else;
> return: array;
> /if;
> /if;
> #fieldvalue = string: ((self -> 'quicksearch_form') -> (getvalue: '-q'));
> if: #fieldvalue != '';
> if: (self -> 'database') -> 'isfilemaker';
> #output -> (insert: -logicaloperator='or');
> iterate: (self -> 'quicksearch_fields'), #field;
> #output -> (insert:  #field = #fieldvalue);
> /iterate;
> else;
> // search each word separately
> #fieldvalue = #fieldvalue -> (split: ' ');
> iterate: #fieldvalue, #onevalue;
> #output_temp = array;
> iterate: (self -> 'quicksearch_fields'), #field;
> if: #_sql;
> #output_temp -> (insert:  (encode_sql: #field )
> + ' LIKE "' + (encode_sql: #onevalue ) + '%"');
> // basic emulation of "word begins with"
> iterate: #wordseparators, #wordseparator;
> #output_temp -> (insert:  (encode_sql: #field )
> + ' LIKE "%' + (encode_sql: #wordseparator + #onevalue ) + '%"');
> /iterate;
> else;
> #output_temp -> (insert:  -op='bw');
> #output_temp -> (insert:  #field = #onevalue );
> if: !(self -> 'database' -> 'isfilemaker');
> // this variant is not needed for FileMaker since it already searches with "word begins with" as default #output_temp -> (insert:  -op='cn');
> iterate: #wordseparators, #wordseparator;
> #output_temp -> (insert:  -op='cn');
> #output_temp -> (insert:  #field = #wordseparator + #onevalue );
> /iterate;
> /if;
> /if;
> /iterate;
> if: #_sql;
> if: #output_temp -> size > 1;
> #output_temp = '(' + #output_temp -> (join: ' OR ') + ')';
> else;
> #output_temp = #output_temp -> first;
> /if;
> #output -> (insert: #output_temp);
> else;
> if: #output_temp -> size > 2;
> #output_temp -> (insert: -opbegin='or', 1);
> #output_temp -> (insert: -opend='or');
> /if;
> #output -> (merge: #output_temp);
> /if;
> /iterate;
>
> if: #_sql;
> if: #output -> size;
> #output = '(' + #output -> (join: ' AND ') + ')';
> else;
> #output = string;
> /if;
> else;
> if: #output -> size;
> #output -> (insert: -opbegin='and', 1);
> #output -> (insert: -opend='and');
> /if;
> /if;
> /if; // isfilemaker
> /if; // #fieldvalue != ''
> return: @#output;
> /define_tag;
>
> define_tag: 'urlargs', // returns all get params that begin with - as a query string
> -optional='except', -copy,
> -optional='prefix', // for example ? or &amp; to include at the beginning of the querystring
> -optional='suffix'; // for example &amp; to include at the end of the querystring
> local: 'output'=array, 'param';
> local: 'clientparams'=client_getparams;
>
> !(local_defined: 'except') ? local: 'except'=array;
> #except -> type != 'array' ? #except = array: #except;
>
> iterate: #clientparams, #param;
> if: #param -> type == 'pair';
> if: #param -> name -> (beginswith: '-') && #except !>> #param -> name;
> #output -> (insert: (#param -> name) + '=' + (#param -> value));
> /if;
> else; // just a string param (no pair)
> if: #param -> (beginswith: '-') && #except !>> #param;
> #output -> (insert: #param);
> /if;
> /if;
> /iterate;
> if: #output -> size;
> return: (local: 'prefix') + (#output -> (join: '&amp;')) + (local: 'suffix');
> /if;
>
> /define_tag;
>
>
> define_tag: 'renderhtml',
> -optional='inlinename';
> local: '_inlinename'=string,
> 'output'=string,
> 'fields'=(self -> 'fields'),
> 'field'=string,
> 'keyfield'=null,
> 'affectedrecord_keyvalue'=null,
> 'record_loop_count'=integer,
> 'db'=@(self -> 'database'),
> 'nav'=@(self -> 'nav'),
> 'dbfieldmap'=@(self -> 'dbfieldmap'),
> 'classarray'=array,
> 'fieldname'=string,
> 'value'=string,
> 'keyparamname',
> 'url';
> if: (local: 'inlinename')!='';
> #_inlinename = #inlinename;
> else: #db -> type == 'database';
> #_inlinename=#db -> 'inlinename';
> #keyfield=#db -> 'keyfield';
> #affectedrecord_keyvalue = #db -> 'affectedrecord_keyvalue';
> /if;
> #output += (self -> (renderheader: -start));
> if: #db -> shown_count >= 10;
> #output += (self -> renderfooter);
> /if;
> #output += '<tbody>';
> records: -inlinename=#_inlinename;
> #record_loop_count = loop_count;
> #output += '\n<tr>';
> iterate: #fields, #field;
> #fieldname = (#dbfieldmap -> (find: (#field -> (find: 'name'))));
> #keyparamname = (#field -> (find: 'keyparamname'));
> #value=(field: #fieldname);
> if: #field -> (find: 'template') -> type == 'map';
> if: #field -> (find: 'template') >> #value;
> #value = #field -> (find: 'template') -> (find: #value);
> else: #field -> (find: 'template') >> -default;
> #value = #field -> (find: 'template') -> (find: -default);
> else;
> // show fieldvalue as is
> /if;
> // substitute field value in the display template
> #value -> (replace: '#value#', (field: #fieldname));
> /if;
> #classarray=array;
> if:  #affectedrecord_keyvalue == (field: #keyfield) && (field: #keyfield) != '';
> // hightlight affected row
> #classarray -> (insert: 'highlight');
> else;
> (#record_loop_count - 1)  % 2 == 0 ? #classarray -> (insert: 'even');
> /if;
> #output += '<td';
> if: #classarray -> size;
> #output += ' class="' + #classarray -> (join: ' ') + '"';
> /if;
> #output += '>';
> if: (#field -> (find: 'url')) != '';
> #url = (#field -> (find: 'url'));
> if: #nav -> type == 'nav' && #url !>> '#value#';
> #output += '<a href="' + (#nav -> (url: -path=#url,
> #keyparamname=(field: #keyfield),
> -urlargs=(self -> (urlargs: -except=(array: -path, #keyparamname)))));
> #output += '">' +  #value
> // show something to click on even if the field is empty
> + ((string_findregexp: #value, -find='\\w*') -> size == 0 ? '(edit)')
> + '</a>';
> else;
> #url -> (replace: '#value#', (field: #fieldname));
> #output += '<a href="' + #url + '"';
> #url -> (beginswith: 'http://') || #url -> (beginswith: 'https://') || #url -> (beginswith: 'mailto:')
> ? #output += ' class="ext"';
> #output += '>' +  #value + '</a>';
> /if;
> else;
> #output += #value;
> /if;
> #output += '</td>\n';
> /iterate;
> #output += '</tr>\n';
> /records;
> #output += '</tbody>\n';
> #output += (self -> (renderfooter: -end));
> return: @#output;
> /define_tag;
>
> define_tag: 'renderheader',
> -optional='start';
> local: 'output'=string,
> 'db'=@(self -> 'database'),
> 'nav'=@(self -> 'nav'),
> 'fields'=@(self -> 'fields'),
> 'field'=string,
> 'classarray'=array;
> (local_defined: 'start') ? #output += '<table>';
> #output += '<thead>\n<tr>';
> if: (self -> 'quicksearch_form') -> type == 'form';
> #output += '<th colspan="' + (#fields -> size) + '" class="quicksearch';
> ((self -> 'quicksearch_form') -> (getvalue: '-q') != '') ? #output += ' highlight';
> #output += '">';
> #output += (self -> 'quicksearch_form') -> renderform;
> if: (self -> 'quicksearch_form_reset') -> type =='form';
> #output += (self -> 'quicksearch_form_reset') -> renderform;
> /if;
> #output += '</th></tr>\n<tr>';
> /if;
> iterate: #fields, #field;
> #classarray=array;
> //(self -> 'quicksearch_form') -> type == 'form' ? #classarray -> (insert: 'notopborder');
> (self -> 'sortfield') == (#field -> (find: 'name')) && !(#field -> (find: 'nosort')) ? #classarray -> (insert: 'sort');
> #output += '<th';
> if: #field -> (find: 'width') > 0;
> #output += ' style="width: ' + (integer: #field -> (find: 'width')) + 'px;"';
> /if;
> if: #classarray -> size;
> #output += ' class="' + #classarray -> (join: ' ') + '"';
> /if;
> #output += '>';
> if: (#field -> (find: 'nosort'));
> #output += '<div>' + (#field -> (find: 'label')) '</div>';
> else;
> if: (#classarray >> 'sort' && (self -> 'sortdescending'));
> // create link to change to unsorted
> #output += '<a href="./'
> + (self -> (urlargs: -except=(array: -sort, -desc, -page), -prefix='?')) + '"'
> + ' title="' + #Unsort + '">';
> else;
> // create link to toggle sort mode
> #output += '<a href="./?-sort=' + (#field -> (find: 'name'))
> + (#classarray >> 'sort' && !(self -> 'sortdescending') ? '&amp;-desc')
> + (self -> (urlargs: -except=(array: -sort, -desc, -page), -prefix='&amp;')) + '"'
> + ' title="' + (#classarray >> 'sort'
> ? (self -> 'changeSortOrd')
> + ((self -> 'sortdescending') ? (self -> 'sortAsc') | (self -> 'sortDes'))
> | (self -> 'sortAscBy') + (encode_html: (#field -> (find: 'label'))) ) + '">';
> /if;
> #output += (#field -> (find: 'label'));
> if: (string_findregexp: (#field -> (find: 'label')), -find='\\S') -> size == 0;
> #output += '&nbsp;'; // to show sort link as block element properly even for empty label
> /if;
> if: #classarray >> 'sort';
> #output += ' <span class="sortmarker"> ' + ((self -> 'sortdescending') ? '&#9660;' | '&#9650;') + '</span>';
> /if;
> #output += '</a>';
> /if;
> #output += '</th>\n';
> /iterate;
> #output += '</tr></thead>\n';
> return: @#output;
> /define_tag;
>
> define_tag: 'renderfooter',
> -optional='end';
> // unicode symbols http://www.alanwood.net/unicode/geometric_shapes.html
> local: 'output'=string,
> 'db'=@(self -> 'database'),
> 'nav'=@(self -> 'nav'),
> 'fields'=@(self -> 'fields'),
> 'field'=string;
> #output += '<tr><th colspan="' + (#fields -> size) + '" class="footer first' + (!(local_defined: 'end') &&false? ' notopborder') + '">';
>
> if: (self -> 'page') > 1;
> #output += ' <a href="?' + (self -> (urlargs: -except=(array: -page), -suffix='&amp;'))
> + '-page=1" class="prevnext"'
> + ' title="' + (self -> 'goFirst') + '">|&#9668;</a> ';
>
> #output += ' <a href="?' + (self -> (urlargs: -except=(array: -page), -suffix='&amp;'))
> + '-page=' + ((self -> 'page') - 1)
> + '" class="prevnext"'
> + ' title="' + (self -> 'goPrev') + '">&#9668;&#9642;&#9642;</a> ';
> else;
> #output += ' <span class="prevnext dim">|&#9668;</span> <span class="prevnext dim">&#9668;&#9642;&#9642;</span> ';
> /if;
> if: #db -> found_count > #db -> shown_count;
> #output += #db -> shown_first + ' - ' #db -> shown_last + ' of ';
> /if;
> #output += #db -> found_count + (self -> 'foundC');
> if: (#db -> shown_last) < (#db -> found_count);
> #output += ' <a href="?' + (self -> (urlargs: -except=(array: -page), -suffix='&amp;'))
> + '-page=' + ((self -> 'page') + 1) + '" class="prevnext"'
> + ' title="' + (self -> 'goNext') + '">&#9642;&#9642;&#9658;</a> ';
> #output += ' <a href="?' + (self -> (urlargs: -except=(array: -page), -suffix='&amp;'))
> + '-page=' + (self -> lastpage) + '" class="prevnext"'
> + ' title="' + (self -> 'goLast') + '">&#9658;|</a> ';
> else;
> #output += ' <span class="prevnext dim">&#9642;&#9642;&#9658;</span>  <span class="prevnext dim">&#9658;|</span> ';
> /if;
> #output += '</th></tr>';
> (local_defined: 'end') ? #output += '</table>\n';
> return: @#output;
> /define_tag;
>
> define_tag: 'page'; return: (self -> 'page'); /define_tag;
>
> define_tag: 'lastpage';
> if: (self -> 'database') -> 'found_count' > 0;
> return: (((self -> 'database') -> 'found_count' - 1) / (self -> 'database') -> 'maxrecords_value') + 1;
> else;
> return: 1;
> /if;
> /define_tag;
>
> define_tag: 'page_skiprecords',
> -required='maxrecords', -type='integer';
> // converts page value to a skiprecords value to use in search
> return: ((self -> 'page') - 1) * #maxrecords;
> /define_tag;
>
>
> define_tag: 'trace',
> -optional='html';
> local: 'eol'=(local_defined: 'html') ? '<br>\n' | '\n';
>
> return: #eol + 'Grid debug trace' + #eol + (self -> 'debug_trace') -> (join: #eol) + #eol;
>
> /define_tag;
>
>
>/define_type;
>
>?>
>#############################################################
>This message is sent to you because you are subscribed to
>the mailing list <[hidden email]>.
>To unsubscribe, E-mail to: <[hidden email]>
>Send administrative queries to  <[hidden email]>
>List archive http://lists.montania.se/Lists/knop/
>(log in with your email and ConfirmationID as password, send message to
><[hidden email]> to get that ID)
>Project homepage http://montania.se/projects/knop/
>AIM chatroom knop aim:gochat?roomname=knop


--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:[hidden email]
 (spam-safe email address, replace '-' with 'a')

#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://lists.montania.se/Lists/knop/
(log in with your email and ConfirmationID as password, send message to
<[hidden email]> to get that ID)
Project homepage http://montania.se/projects/knop/
AIM chatroom knop aim:gochat?roomname=knop

Loading...