EditableBulletList

From $1

  • You do not have permissions to view this page - please try logging in.
  • You do not have permissions to view this page - please try logging in.
  • You do not have permissions to view this page - please try logging in.
  • You do not have permissions to view this page - please try logging in.
Table of contents
No headers
/***

    EditableBulletList

    (optional) values : list

    (optional) noValuesLabel : str

    (optional) editLabel : str

    (optional) addLabel : str

    (optional) saveLabel : str

    (optional) cancelLabel : str

    (optional) publish : str

    (optional) class : str

    (optional) readOnly : bool

    (optional) readOnlyAlert : str

    (optional) message : map

***/

// TODO (steveb):
// 1) reset the contents of the textboxes when the edit operation is canceled
// 2) update the bullet list after save is confirmed


// read parameters
var values = $values ?? [ ];
var novalueslabel = $novalueslabel ?? 'There are no values.';
var editlabel = $editlabel ?? 'edit';
var addlabel = $addlabel ?? 'add';
var savelabel = $savelabel ?? 'save';
var cancellabel = $cancellabel ?? 'cancel';
var channel = $publish ?? 'default';
var class = $class;
var readonly = $readonly ?? user.anonymous;
var readonlyalert = $readonlyalert ?? 'You must login to edit these values.';
var message = $message ?? { };

// render controls
<div id=(@div) class=(class)>

    // check if the edit button should be enabled
    if(readonly) {
        <input type="button" value=(editlabel) id=(@edit) ctor="
            when($this.click) alert({{ readonlyalert }});
        "/>
    } else {
        <input type="button" value=(editlabel) id=(@edit) ctor="
            when($this.click) @toggle();
        "/>
    }
    
    // render current values as a bulleted list
    <div id=(@displayspan)>
        if(#values == 0) {
            <div id=(@resizeonedit)>
                novalueslabel
            </div>
        } else {
            <ul>
                foreach(var value in values) {
                    <li> value </li>
                }
            </ul>
        }
    </div>
    
    // render the edit form
    <form id=(@changeform)>
        if(#values != 0) {
            foreach(var value in values) {
                <textarea>
                    value
                </textarea>
            }
        } else {
            <textarea />
        }

        // separate the input boxes from the controls
        <div class="cleardiv"> &nbsp; </div>

        // render the add button
        <input type="button" id=(@add) value=(addlabel) ctor="
            when($this.click) $('#' + {{ @changeform }} + ' textarea:last').after('<textarea></textarea>');
        "/>
        
        // render the save button
        &nbsp;;
        <input type="button" id=(@save) value=(savelabel) ctor="
            when($this.click) {
                var newvalues = [ ];
                $('#' + {{ @changeform }} + ' textarea').each(function() {
                    var val = $(this).val();
                    if(val != '') newvalues.push(val);
                });
                var msg = {{ message }};
                msg.values = newvalues;
                msg.completed = function() { @toggle(); };
                Deki.publish({{ channel }}, msg);
            }
        "/>

        // render the cancel button
        &nbsp;;
        <input type="button" id=(@cancel) value=(cancellabel) ctor="
            when($this.click) @toggle();
        "/>
    </form>
</div>

// script
<script type="text/jem">"
when(@toggle) {
    $('#' + {{ @changeform }} + ',#' + {{ @displayspan }} + ',#' + {{ @edit }}).slideToggle();
    var resizeonedit = $('#' + {{ @resizeonedit }});
    if(resizeonedit.css('padding-top') == '0px') {
        resizeonedit.css('padding-top', '1.6em');
    } else {
        resizeonedit.css('padding-top', '0px');
    }
}
"</script>

// styles
<style type="text/css">"
#" .. @resizeonedit .. " {
    padding-top: 1.6em;
}
#" .. @changeform .. " {
    display: none;
}
#" .. @changeform .. " textarea {
    width: 50%;
    float: left;
    margin-bottom: 5px;
}
#" .. @div .. " .cleardiv {
    height:1px;
    clear:both;
}
"</style>
Tags: (Edit tags)
  • No tags
 
Comments (0)
You must login to post a comment.

 
Powered by MindTouch Core

Disclaimer: Vespa Labs contains information that is VERY likely to wreck your scooter and possibly yourself both intentionally (i.e. gaining more peformance while sacrificing reliability + safety) and unintentionally (i.e. misleading or incorrect information). Vespa Labs is only a wiki and intended as a dumping ground for information and not as a properly reviewed source. The same disclaimers that wikipedia.org use apply to Vespa Labs. The short version is use information at your own risk, both information on the main wiki and in the user areas are intended to be used only as "thought provoking" for someone that knows what they are doing. If you try to implement a "thought" Vespa Labs is not reponsible and if something goes wrong we hope that you live and update the offending information with corrections to warn others.

Vespa Labs is an international site and therefore may contain information that is not road legal in some countries/states and may also invalidate insurance policies. Treat all information as experimental and for "race use only" (i.e. not for road use - even if it is implied or explicitly stated). Refer to and adhere to your local road and legal rules, as well as the manufacturers recommendations.