storkCore

Check-in [9b5bcb6207]
Login

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

Overview
Comment: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.
Timelines: family | ancestors | descendants | both | emptySublist
Files: files | file ages | folders
SHA1:9b5bcb6207fa13e799825bb958d425b6bbf336a5
User & Date: setok 2018-02-12 19:55:11
Context
2018-02-13
15:22
Cleaner implementation for the empty sublist check for listoflists check-in: da040a306b user: setok tags: emptySublist
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
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to list.js.

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
...
152
153
154
155
156
157
158

159
160
161
162
163
164
165


166
167
168
169
170
171
172
...
828
829
830
831
832
833
834
835



836
837



838
839
840
841
842
843
844
845
846

847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866

867

868


869
870
871
872
873
874
875

/**
 * Sets 'listModel' (a ListModel object) to be the model for this list.
 * Each element in the model will be given its own controller, cloned from one
 * set with setItemControllerPrototype() - which must be called before
 * calling this.
 *
 * init() will not be called on this clone.
 *
 * Each item controller will get a StorkModel based on the content of the
 * element of 'listModel'.
 */
ListController.setModel = function(listModel) {
    if(!this.itemControllerProto) {
        throw "You need to set the item controller prototype (setItemControllerPrototype) before calling setModel!";
    }
................................................................................
            removeClass(this.zeroLengthElement, "hidden");
        } else {
            removeClass(this.containerElement, "hidden");
            addClass(this.zeroLengthElement, "hidden");
        }
    }
};


/**
 *
 */
ListController.resetEvent = function(listModel) {
    this.setModel(listModel);
};


/**
 *
 */
ListController.sortEvent = function(listModel) {
    var itemControllers=this.itemControllers.slice();
    var sortedControllers=[];
    var i;
................................................................................


/**
 * Override ListItemController refresh() to implement functionality of
 * renderIfEmpty().
 */

ListOfListsItem.refresh = function() {    



    if (! this.renderIfEmpty) {
        var sublistModel = this.getSubListController().getModel();




        if (!sublistModel || (sublistModel.getLength() == 0)) {
            hideElement(this.myElement);
        } else {
            showElement(this.myElement);
        }                
    }
        
    this.superMethod(ListOfListsItem.refresh, "refresh");

};


/**
 * Override the normal ListItemController createElement() with one that
 * builds the sub-list.
 */
ListOfListsItem.createElement = function(containerElement,
                                         beforeElement) {
    var subListModel;
    var listContainer;

    //console.debug("ListOfListsItem - createElement");
    this.superMethod(ListOfListsItem.createElement, "createElement", 
                     containerElement, beforeElement);

    listContainer = this.getContainedElement(this.subListContainer);
    this.subListController.setListContainer(listContainer);

    subListModel = this.model.getProperty(this.subListModelProperty);

    this.subListController.setModel(subListModel);

    subListModel.addListener(this);


};


ListOfListsItem.renderIfEmpty = function(render) {
    this.renderIfEmpty = render;
    return;
};







<
<







 







>







>
>







 







|
>
>
>


>
>
>






|
|
|
>












|







>

>

>
>







80
81
82
83
84
85
86


87
88
89
90
91
92
93
...
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
...
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
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
878
879
880
881
882
883
884
885
886
887

/**
 * Sets 'listModel' (a ListModel object) to be the model for this list.
 * Each element in the model will be given its own controller, cloned from one
 * set with setItemControllerPrototype() - which must be called before
 * calling this.
 *


 * Each item controller will get a StorkModel based on the content of the
 * element of 'listModel'.
 */
ListController.setModel = function(listModel) {
    if(!this.itemControllerProto) {
        throw "You need to set the item controller prototype (setItemControllerPrototype) before calling setModel!";
    }
................................................................................
            removeClass(this.zeroLengthElement, "hidden");
        } else {
            removeClass(this.containerElement, "hidden");
            addClass(this.zeroLengthElement, "hidden");
        }
    }
};


/**
 *
 */
ListController.resetEvent = function(listModel) {
    this.setModel(listModel);
};


/**
 *
 */
ListController.sortEvent = function(listModel) {
    var itemControllers=this.itemControllers.slice();
    var sortedControllers=[];
    var i;
................................................................................


/**
 * Override ListItemController refresh() to implement functionality of
 * renderIfEmpty().
 */

ListOfListsItem.refresh = function() { 
    console.log("refresh");
    var r = this.superMethod(ListOfListsItem.refresh, "refresh");

    if (! this.renderIfEmpty) {
        var sublistModel = this.getSubListController().getModel();
        console.log(this.getSubListController());
        console.log(sublistModel);            
        console.log(this.myElement);

        if (!sublistModel || (sublistModel.getLength() == 0)) {
            hideElement(this.myElement);
        } else {
            showElement(this.myElement);
        }                
    }        

    console.log("ListOfListsItem.refresh - return");
    return r;
};


/**
 * Override the normal ListItemController createElement() with one that
 * builds the sub-list.
 */
ListOfListsItem.createElement = function(containerElement,
                                         beforeElement) {
    var subListModel;
    var listContainer;

    console.debug("ListOfListsItem - createElement");
    this.superMethod(ListOfListsItem.createElement, "createElement", 
                     containerElement, beforeElement);

    listContainer = this.getContainedElement(this.subListContainer);
    this.subListController.setListContainer(listContainer);

    subListModel = this.model.getProperty(this.subListModelProperty);
    console.log("createElement setModel");
    this.subListController.setModel(subListModel);
    console.log("createElement addListener");
    subListModel.addListener(this);
    console.log("createElement return");
    this.refresh();
};


ListOfListsItem.renderIfEmpty = function(render) {
    this.renderIfEmpty = render;
    return;
};