storkCore

Check-in [953053e8fb]
Login

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

Overview
Comment:(no comment)
Timelines: family | ancestors | descendants | both | emptySublist
Files: files | file ages | folders
SHA1:953053e8fbefd038865fb9a0de405f6b71e89f45
User & Date: setok 2018-02-06 18:22:35
Context
2018-02-12
19:55
This version works for not displaying empty sublists However there is two calls to refresh() along the path to make that happen (due to the model not being ready on the first call). Need to figure out a way to avoid that. check-in: 9b5bcb6207 user: setok tags: emptySublist
2018-02-06
18:22
(no comment) check-in: 953053e8fb user: setok tags: emptySublist
12:28
(no comment) Leaf check-in: acabda570e user: setok tags: trunk
09:30
Added support in ListOfListItem for only rendering if sublist has content This means that e.g. sections with empty sublists can be set to not appear. check-in: 52a362b577 user: setok tags: emptySublist
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added examples/clonedListModel.html.





























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title></title>
        <script type="text/javascript" src="../storkCore.js">
            </script>
        <script type="text/javascript" src="../list.js">
            </script>

</head>

<body>
<h1></h1>

<p>
The following lists should have different content. Two models are
created, one cloned from the other, with a list model within that is
used for the content. Normally that would lead to them having the same
content, but the list model ("items") is specified to be a
clonedProperty of the containing model, which means the two models do
not point to the same list model.
<h2>First List</h2>
<ul id="list1">  <!-- Container element -->
  <!-- Actual list items will be copied into here -->
</ul>


<h2>Second List</h2>
<ul id="list2">  <!-- Container element -->
  <!-- Actual list items will be copied into here -->
</ul>


<div style="display: none;">
  <ul>
    <!-- 'Template' for each item in the list -->
    <li id="item_#n"><span id="text_#n"></span></li>
  </ul>
</div>        


<hr>
<address></address>
<!-- hhmts start -->Last modified: Tue Feb  6 13:15:47 EET 2018 <!-- hhmts end -->
</body>
<script type="text/javascript">
var firstList = clone(ListController);
firstList.setListContainer(elementByID("list1"));

var listItem = clone(ListItemController);
listItem.setItemTemplate(elementByID("item_#n"));
listItem.linkTextProperty("text", "text");
firstList.setItemControllerPrototype(listItem);

var firstModel = clone(StorkModel);
firstModel.setProperty("items", clone(ListModel));
firstModel.clonedProperty("items", ListModel);

var secondModel = clone(firstModel);

firstItems = firstModel.getProperty("items");
firstItems.pushObject({text: "Foo"});
firstItems.pushObject({text: "Bar"});

var secondList = clone(ListController);
secondList.setListContainer(elementByID("list2"));
secondList.setItemControllerPrototype(listItem);

secondItems = secondModel.getProperty("items");
secondItems.pushObject({text: "Goo"});
secondItems.pushObject({text: "Gah"});

firstList.setModel(firstModel.getProperty("items"));
secondList.setModel(secondModel.getProperty("items"));

        </script>


        </html>

Changes to storkCore.js.

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
..
71
72
73
74
75
76
77




78
79
80
81
82
83
84
...
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
...
516
517
518
519
520
521
522




523
524
525
526
527
528
529
530
531
532
533
534
535

536
537
538
539
540
541
542
...
947
948
949
950
951
952
953




















954
955
956
957
958
959
960
            proto = object.constructor.prototype;
        }
    }
    else {
        proto = Object.getPrototypeOf(object);
    }
    return proto;
}

/**
 *
 * A clone of an object is an empty object
 * with a prototype reference to the original.
 *
 * For StorkCore we're using an OO model like Self, where there are no
................................................................................
 *
 * @param {Object} obj
 *      the object to be cloned
 * @return {Object}
 *      the cloned object
 */
function clone(obj) {




    // a private constructor, used only by this one clone.
    function Clone() {
        this._base = obj;
        //console.info("object: %s", obj);
    }

    Clone.prototype = obj;
................................................................................
    };
})();

function logError(error) {
    if(window.console && window.console.error) {
        window.console.error(error);
    }
}

/**
 * Similar to document.getElementByID, but throws an error if not found.
 */

function elementByID(id) {
    var element = document.getElementById(id);
    if (element == undefined) {
        throw "Element '" + id + "' could not be found";
    } else {
        return element;
    }
}


/**
 * Search through element and its children to find the element with 'id' and
 * return it.
 */

................................................................................
/**
 * Returns a copy of the object, by creating a new object and copying
 * each property and returning the new object. This does not do a deep
 * copy. Any objects properties point to are not copied, just the references
 */
function objectCopy(source) {
    var ob;





    if (source instanceof Array) {
        ob = [];
    } else {
        ob = {};
    }

    for (var key in source) {
        ob[key] = source[key];
    }

    return ob;
}



function hideElement(element) {
    element.setAttribute("hidden", "");
    // Can be used in CSS for those browsers that don't support the 'hidden'
    // attribute
    addClass(element, "hidden");
................................................................................
    if (this.modelProperties[key] != undefined) {
        return true;
    } else {
        return false;
    }
};






















/**
 * @protected
 * calls all the listeners for the model properties value change. The listeners
 * should have a method named "propertyChangeEvent" which receives parameters
 *  (model, property, oldvalue, newValue)
 *







|







 







>
>
>
>







 







|












|







 







>
>
>
>












|
>







 







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







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
..
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
...
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
...
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
...
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
983
984
985
986
987
988
989
            proto = object.constructor.prototype;
        }
    }
    else {
        proto = Object.getPrototypeOf(object);
    }
    return proto;
};

/**
 *
 * A clone of an object is an empty object
 * with a prototype reference to the original.
 *
 * For StorkCore we're using an OO model like Self, where there are no
................................................................................
 *
 * @param {Object} obj
 *      the object to be cloned
 * @return {Object}
 *      the cloned object
 */
function clone(obj) {
    if ( (obj === undefined) || (obj === null) ) {
        return obj;
    }

    // a private constructor, used only by this one clone.
    function Clone() {
        this._base = obj;
        //console.info("object: %s", obj);
    }

    Clone.prototype = obj;
................................................................................
    };
})();

function logError(error) {
    if(window.console && window.console.error) {
        window.console.error(error);
    }
};

/**
 * Similar to document.getElementByID, but throws an error if not found.
 */

function elementByID(id) {
    var element = document.getElementById(id);
    if (element == undefined) {
        throw "Element '" + id + "' could not be found";
    } else {
        return element;
    }
};


/**
 * Search through element and its children to find the element with 'id' and
 * return it.
 */

................................................................................
/**
 * Returns a copy of the object, by creating a new object and copying
 * each property and returning the new object. This does not do a deep
 * copy. Any objects properties point to are not copied, just the references
 */
function objectCopy(source) {
    var ob;

    if ( (source === undefined) || (source === null) ) {
        return source;
    }

    if (source instanceof Array) {
        ob = [];
    } else {
        ob = {};
    }

    for (var key in source) {
        ob[key] = source[key];
    }

    return ob;
};



function hideElement(element) {
    element.setAttribute("hidden", "");
    // Can be used in CSS for those browsers that don't support the 'hidden'
    // attribute
    addClass(element, "hidden");
................................................................................
    if (this.modelProperties[key] != undefined) {
        return true;
    } else {
        return false;
    }
};


StorkModel.cloned = function() {
    var i, property;

    this.superMethod(StorkModel.cloned, "cloned");
    //this.listeners = objectCopy(this.listeners);
    //this.copyProperties = objectCopy(this.copyProperties);
    for (i = 0; i < this.copyProperties.length; i++) {
        property = this.copyProperties[i];
        this.modelProperties[property] = 
            objectCopy(this.modelProperties[property]);
    }

    //this.cloneProperties = objectCopy(this.cloneProperties);
    for (i=0; i < this.cloneProperties.length; i++) {
        property = this.cloneProperties[i];
        this.modelProperties[property] = clone(this.modelProperties[property]);
    }
};


/**
 * @protected
 * calls all the listeners for the model properties value change. The listeners
 * should have a method named "propertyChangeEvent" which receives parameters
 *  (model, property, oldvalue, newValue)
 *