storkCore

Check-in [5aecbe5f8e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added push() to ListModel for pushing StorkModel objects directly.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:5aecbe5f8e7fd3e8bcd6980002b5c4e893576496
User & Date: setok 2018-01-29 15:30:39
Context
2018-01-30
19:57
Changed tests/ to examples/ While these are used for testing as well, they serve as examples for other possible users too, and are not anyway built with any kind of test framework. check-in: 849d2de981 user: setok tags: trunk
2018-01-29
15:30
Added push() to ListModel for pushing StorkModel objects directly. check-in: 5aecbe5f8e user: setok tags: trunk
14:43
Removed inaccurate comment check-in: 50fdee7b6e user: setok tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to list.js.

936
937
938
939
940
941
942
















943
944
945
946
947
948
949
950
951
952
953

954

955
956
957
958
959
960
961
962
963
964
965
966
ListModel.insertObjectBefore = function(object, index) {
    var model = StorkModel.createFromObject(object);
    this.items.splice(index, 0, model);
    this.informListeners("insertBeforeEvent", [this, model, index]);
    return model;
};


















/**
 * Insert a list item model object, based on 'object' to end of list.
 *
 * @param {Object} object is any Javascript object. Each property of it will
 *          be made into a StorkModel property.
 *
 *          Calls insertBeforeEvent(sourceModel, model, index) for each
 *          listener, where 'sourceModel' is this ListModel, 'model' is the
 *          added model
 *

 */

ListModel.pushObject = function(object) {
    var model = StorkModel.createFromObject(object);
    this.items.push(model);
    this.informListeners("insertBeforeEvent",
                         [this, model, this.items.length-1]);
    return model;
};


/**
 *
 */







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>











>

>


|
<
<







936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975


976
977
978
979
980
981
982
ListModel.insertObjectBefore = function(object, index) {
    var model = StorkModel.createFromObject(object);
    this.items.splice(index, 0, model);
    this.informListeners("insertBeforeEvent", [this, model, index]);
    return model;
};


/**
 * Insert a list item model object into the list.
 *
 *          Calls insertBeforeEvent(sourceModel, model, index) for each
 *          listener, where 'sourceModel' is this ListModel, 'model' is the
 *          added model
 */

ListModel.push = function(storkModel) {
    this.items.push(storkModel);
    this.informListeners("insertBeforeEvent",
                         [this, storkModel, this.items.length-1]);
    return;
};


/**
 * Insert a list item model object, based on 'object' to end of list.
 *
 * @param {Object} object is any Javascript object. Each property of it will
 *          be made into a StorkModel property.
 *
 *          Calls insertBeforeEvent(sourceModel, model, index) for each
 *          listener, where 'sourceModel' is this ListModel, 'model' is the
 *          added model
 *
 * @return Return created StorkModel object from 'object'.
 */

ListModel.pushObject = function(object) {
    var model = StorkModel.createFromObject(object);
    this.push(model);


    return model;
};


/**
 *
 */

Changes to storkCore.js.

852
853
854
855
856
857
858


859
860
861
862
863
864
865
866
867

868
869
870
871
872
873
874
 */
StorkModel.addListener = function(listener) {
    if (!listener){
        throw new Error("Empty object passed to StorkModel.addListener");
    }
    this.listeners.push(listener);
};


/**
 * Remove an object listening for changes in the attributes of this model
 *
 * @param {Object} listener
 *    the object registered as listener to be deleted
 */
StorkModel.removeListener = function(listener) {
    this.listeners = removeFromArray(this.listeners, listener);
};


/**
 * applies to this model properties all the properties in an object passed as
 * argument
 *
 * @param {Object} properties object from which to set the properties into this
 *      model properties







>
>









>







852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
 */
StorkModel.addListener = function(listener) {
    if (!listener){
        throw new Error("Empty object passed to StorkModel.addListener");
    }
    this.listeners.push(listener);
};


/**
 * Remove an object listening for changes in the attributes of this model
 *
 * @param {Object} listener
 *    the object registered as listener to be deleted
 */
StorkModel.removeListener = function(listener) {
    this.listeners = removeFromArray(this.listeners, listener);
};


/**
 * applies to this model properties all the properties in an object passed as
 * argument
 *
 * @param {Object} properties object from which to set the properties into this
 *      model properties

Changes to tests/listoflists.html.

11
12
13
14
15
16
17





18
19
20
21
22
23
24
25
            </script>

        <script type="text/javascript" src="../list.js">
            </script>
        
    </head>
    <body>





      <div style="border: solid red 2px;" id="sectionedList">
      </div>
      <div style="display: none;">
        <!-- section -->
        <div style="border: solid black 1px;" id="section_#n">
          <h3 id="sectionTitle_#n"></h3>
          <ul id="sublist_#n"></ul>
        </div>







>
>
>
>
>
|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
            </script>

        <script type="text/javascript" src="../list.js">
            </script>
        
    </head>
    <body>
<p>
Below should be two sections, with "Foo, Bar" in the first section as
bullets and "Goo, Gah" in the second section.
</p>

<div style="border: solid red 2px;" id="sectionedList">
      </div>
      <div style="display: none;">
        <!-- section -->
        <div style="border: solid black 1px;" id="section_#n">
          <h3 id="sectionTitle_#n"></h3>
          <ul id="sublist_#n"></ul>
        </div>