Skip to content

Commit

Permalink
insertBefore renamed to prepend ,insertAfter renamed to append in rep…
Browse files Browse the repository at this point in the history
…eater.js and repeaterutil
  • Loading branch information
vineetsemwal committed Mar 9, 2013
1 parent 78bf258 commit 3df031c
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 61 deletions.
20 changes: 10 additions & 10 deletions wicket-quickview/src/main/java/com/aplombee/IRepeaterUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,40 @@
*/
public interface IRepeaterUtil {
/**
* insertBefore js call ,creates a new dom tag element as the first element of parent
* prepend js call ,creates a new dom tag element as the first element of parent
*
* @param tag repeater tag
* @param id repeater markupid
* @param parentId parent markupid
* @return insertBefore call of js
* @return prepend call of js
*/
String insertBefore(String tag, String id, String parentId);
String prepend(String tag, String id, String parentId);

/**
* insertBefore js call ,creates a new dom tag element as the first element of parent
* prepend js call ,creates a new dom tag element as the first element of parent
*
* @param component repeater
* @param parent parent to which repeater is added
* @return insertBefore call of js
* @return prepend call of js
*/
String insertBefore(MarkupContainer component, MarkupContainer parent);
String prepend(MarkupContainer component, MarkupContainer parent);

/**
* creates a new dom tag element as the last element of parent with parentId
* @param tag repeater tag
* @param id repeater markupid
* @param parentId parent markupid
* @return insertAfter call of js
* @return append call of js
*/
String insertAfter(String tag, String id, String parentId);
String append(String tag, String id, String parentId);

/**
* creates a new dom tag element as the last element of parent
* @param c repeater
* @param parent parent
* @return insertAfter js call
* @return append js call
*/
String insertAfter(MarkupContainer c, MarkupContainer parent);
String append(MarkupContainer c, MarkupContainer parent);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public QuickGridView<T> addRowAtStart(RowItem<T> rowItem) {
return this;
}

String call = getRepeaterUtil().insertBefore(rowItem, _getParent());
String call = getRepeaterUtil().prepend(rowItem, _getParent());
getSynchronizer().getPrependScripts().add(call);
getSynchronizer().add(rowItem);
return this;
Expand All @@ -158,7 +158,7 @@ public QuickGridView<T> addRow(RowItem<T> rowItem) {
if (!isAjax()) {
return this;
}
String call = getRepeaterUtil().insertAfter(rowItem, _getParent());
String call = getRepeaterUtil().append(rowItem, _getParent());
Synchronizer listener = getSynchronizer();
listener.getPrependScripts().add(call);
listener.add(rowItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ public MarkupContainer add(final Component... components) {

for (int i = 0; i < components.length; i++) {
MarkupContainer parent = _getParent();
String script = getRepeaterUtil().insertAfter((Item)components[i], parent);
String script = getRepeaterUtil().append((Item) components[i], parent);
getSynchronizer().getPrependScripts().add(script);
}
getSynchronizer().add(components);
Expand Down Expand Up @@ -597,7 +597,7 @@ public MarkupContainer addAtStart(final Component... components) {

for (int i = 0; i < components.length; i++) {
MarkupContainer parent = _getParent();
String updateBeforeScript = getRepeaterUtil().insertBefore((Item)components[i], parent);
String updateBeforeScript = getRepeaterUtil().prepend((Item) components[i], parent);
getSynchronizer().getPrependScripts().add(updateBeforeScript);
}
getSynchronizer().add(components);
Expand Down
19 changes: 8 additions & 11 deletions wicket-quickview/src/main/java/com/aplombee/RepeaterUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.util.lang.Args;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* @author Vineet Semwal
*/
Expand Down Expand Up @@ -52,8 +49,8 @@ public RepeaterUtil(Application application) {
/**
* {@inheritDoc}
*/
public String insertBefore(String tag, String markupId, String parentMarkupId) {
String script = String.format("QuickView.insertBefore('%s','%s','%s');", tag, markupId, parentMarkupId);
public String prepend(String tag, String markupId, String parentMarkupId) {
String script = String.format("QuickView.prepend('%s','%s','%s');", tag, markupId, parentMarkupId);
return script;
}

Expand All @@ -62,8 +59,8 @@ public String insertBefore(String tag, String markupId, String parentMarkupId) {
* {@inheritDoc}
*/
@Override
public String insertBefore(MarkupContainer component, MarkupContainer parent) {
String script = insertBefore(getComponentTag(component).getName(), component.getMarkupId(), parent.getMarkupId());
public String prepend(MarkupContainer component, MarkupContainer parent) {
String script = prepend(getComponentTag(component).getName(), component.getMarkupId(), parent.getMarkupId());
return script;
}

Expand All @@ -72,8 +69,8 @@ public String insertBefore(MarkupContainer component, MarkupContainer parent) {
* {@inheritDoc}
*/
@Override
public String insertAfter(String tag, String markupId, String parentMarkupId) {
String script = String.format("QuickView.insertAfter('%s','%s','%s');", tag, markupId, parentMarkupId);
public String append(String tag, String markupId, String parentMarkupId) {
String script = String.format("QuickView.append('%s','%s','%s');", tag, markupId, parentMarkupId);
return script;

}
Expand All @@ -93,8 +90,8 @@ public ComponentTag getComponentTag(Component c) {
* {@inheritDoc}
*/
@Override
public String insertAfter(MarkupContainer c, MarkupContainer parent) {
return insertAfter(getComponentTag(c).getName(), c.getMarkupId(), parent.getMarkupId());
public String append(MarkupContainer c, MarkupContainer parent) {
return append(getComponentTag(c).getName(), c.getMarkupId(), parent.getMarkupId());
}

/**
Expand Down
27 changes: 13 additions & 14 deletions wicket-quickview/src/main/java/com/aplombee/repeater.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
var QuickView = {
/**
creates a new dom element with tag and id provided in parameters
creates a new dom element with tag and id provided in parameters
*/
createItem: function(tag, theId) {
return $("<" + tag + ">").attr("id", theId);
Expand All @@ -32,50 +32,49 @@ var QuickView = {
$("#" + id).remove();
},
/**
creates a new dom tag element as the last element of dome element with id parentContainerId
*/
insertAfter: function(tag, theId, parentContainerId) {
creates a new dom tag element as the last element of dome element with id parentContainerId
*/
append: function(tag, theId, parentContainerId) {
var item = QuickView.createItem(tag, theId);
$("#" + parentContainerId).append(item);
},

/**
creates a new dom tag element as the first element of element with parentContainerId
creates a new dom tag element as the first element of element with parentContainerId
*/
insertBefore: function(tag, theId, parentContainerId) {
prepend: function(tag, theId, parentContainerId) {
var item = QuickView.createItem(tag, theId);
$("#" + parentContainerId).prepend(item);
},
/**
position the scrollbar to bottom
*/
position the scrollbar to bottom
*/
scrollToBottom: function(id)
{
var element = $("#" + id);
scrollTo(id, $(element).height());
},
/**
position the scrollbar to top
position the scrollbar to top
*/
scrollToTop: function(id) {
scrollTo(id, 0);
},
/**
position the scrollbar to provided height
position the scrollbar to provided height
*/
scrollTo: function(id, height) {
var element = $("#" + id);
$(element).scrollTop(height);
},
/**
returns true if the scrollbar of element with parameter id is moved at the bottom else it returns false
*/
returns true if the scrollbar of element with parameter id is moved at the bottom else it returns false
*/
isComponentScrollBarAtBottom: function(id) {
var el = $("#" + id);
return ($(el).prop("offsetHeight") + $(el).scrollTop() >= $(el).prop("scrollHeight"));
},
/**
returns true if the scrollbar of the page is moved at the bottom else it returns false
returns true if the scrollbar of the page is moved at the bottom else it returns false
*/
isPageScrollBarAtBottom: function() {
return (($(window).height() + $(window).scrollTop()) >= $(document).height());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ public void addRow_1(){
final String call="insert after";
QuickGridView.RowItem row=Mockito.mock(QuickGridView.RowItem.class);
final MarkupContainer parent=Mockito.mock(MarkupContainer.class);
Mockito.when(util.insertAfter(row,parent)).thenReturn(call);
Mockito.when(util.append(row, parent)).thenReturn(call);
QuickGridView<Integer> grid=new QuickGridView<Integer>("grid",provider) {
@Override
protected void populate(CellItem<Integer> item) {
Expand Down Expand Up @@ -802,7 +802,7 @@ public void addRow_2(){
final String call="insert after";
QuickGridView.RowItem row=Mockito.mock(QuickGridView.RowItem.class);
final MarkupContainer parent=Mockito.mock(MarkupContainer.class);
Mockito.when(util.insertAfter(row,parent)).thenReturn(call);
Mockito.when(util.append(row, parent)).thenReturn(call);
QuickGridView<Integer> grid=new QuickGridView<Integer>("grid",provider) {
@Override
protected void populate(CellItem<Integer> item) {
Expand Down Expand Up @@ -857,7 +857,7 @@ public void addRowAtStart_1(){
final String call="insert before";
QuickGridView.RowItem row=Mockito.mock(QuickGridView.RowItem.class);
final MarkupContainer parent=Mockito.mock(MarkupContainer.class);
Mockito.when(util.insertBefore(row,parent)).thenReturn(call);
Mockito.when(util.prepend(row, parent)).thenReturn(call);
QuickGridView<Integer> grid=new QuickGridView<Integer>("grid",provider) {
@Override
protected void populate(CellItem<Integer> item) {
Expand Down
14 changes: 7 additions & 7 deletions wicket-quickview/src/test/java/com/aplombee/QuickViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public IRepeaterUtil getRepeaterUtil() {

};
final String script = "script..";
Mockito.when(util.insertAfter(c, parent)).thenReturn(script);
Mockito.when(util.append(c, parent)).thenReturn(script);
QuickView<TestObj> sparc = Mockito.spy(quickView);
sparc.add(c);

Expand Down Expand Up @@ -280,8 +280,8 @@ public Synchronizer getSynchronizer() {
}
};
final String script = "script..", script2 = "script2!";
Mockito.when(util.insertAfter(c, parent)).thenReturn(script);
Mockito.when(util.insertAfter(c2, parent)).thenReturn(script2);
Mockito.when(util.append(c, parent)).thenReturn(script);
Mockito.when(util.append(c2, parent)).thenReturn(script2);
QuickView sparc = Mockito.spy(arc);
sparc.add(c, c2);
Mockito.verify(sparc, Mockito.times(1)).simpleAdd(c, c2);
Expand Down Expand Up @@ -331,7 +331,7 @@ public IRepeaterUtil getRepeaterUtil() {

};
final String script = "script..";
Mockito.when(util.insertAfter(c, parent)).thenReturn(script);
Mockito.when(util.append(c, parent)).thenReturn(script);
QuickView<TestObj> sparc = Mockito.spy(arc);
sparc.add(c);

Expand Down Expand Up @@ -577,7 +577,7 @@ public IRepeaterUtil getRepeaterUtil() {

};
final String script = "script..";
Mockito.when(util.insertBefore(c, parent)).thenReturn(script);
Mockito.when(util.prepend(c, parent)).thenReturn(script);
QuickView sparc = Mockito.spy(quickView);
sparc.addAtStart(c);
Mockito.verify(sparc, Mockito.times(1)).simpleAdd(c);
Expand Down Expand Up @@ -631,8 +631,8 @@ public Synchronizer getSynchronizer() {
}
};
final String script = "script..", script2 = "script2!";
Mockito.when(util.insertBefore(c, parent)).thenReturn(script);
Mockito.when(util.insertBefore(c2, parent)).thenReturn(script2);
Mockito.when(util.prepend(c, parent)).thenReturn(script);
Mockito.when(util.prepend(c2, parent)).thenReturn(script2);
QuickView sparc = Mockito.spy(arc);
sparc.addAtStart(c, c2);
Mockito.verify(sparc, Mockito.times(1)).simpleAdd(c, c2);
Expand Down
24 changes: 12 additions & 12 deletions wicket-quickview/src/test/java/com/aplombee/RepeaterUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public void get_1() {
}

@Test(groups = {"utilTests"})
public void insertBefore_1() {
public void prepend_1() {
final String child = "child", parent = "parent", tag = "div";
String actual = RepeaterUtil.get().insertBefore(tag, child, parent);
String expected = "QuickView.insertBefore('div','child','parent');";
String actual = RepeaterUtil.get().prepend(tag, child, parent);
String expected = "QuickView.prepend('div','child','parent');";
Assert.assertEquals(actual.trim(), expected.trim());
}

@Test(groups = {"utilTests"})
public void insertBefore_2() {
public void prepend_2() {
QuickMockApplication app = new QuickMockApplication();
WicketTester tester = new WicketTester(app);
final QuickViewParent parent = new QuickViewParent("parent");
Expand All @@ -80,8 +80,8 @@ public QuickViewParent newParent() {
};
tester.startComponentInPage(panel);
final Item<Integer> item = (Item) quickView.get(0);
String expected = String.format("QuickView.insertBefore('%s','%s','%s');", TestQuickViewContainer.TAG_NAME, item.getMarkupId(), parent.getMarkupId());
String actual = RepeaterUtil.get().insertBefore(item, parent);
String expected = String.format("QuickView.prepend('%s','%s','%s');", TestQuickViewContainer.TAG_NAME, item.getMarkupId(), parent.getMarkupId());
String actual = RepeaterUtil.get().prepend(item, parent);
Assert.assertEquals(actual.trim(), expected.trim());
}

Expand Down Expand Up @@ -163,16 +163,16 @@ public QuickViewParent newParent() {
}

@Test(groups = {"utilTests"})
public void insertAfter_1() {
public void append_1() {
final String child = "child", parent = "parent", tag = "div";
String call = RepeaterUtil.get().insertAfter(tag, child, parent);
String expected = "QuickView.insertAfter('div','child','parent');";
String call = RepeaterUtil.get().append(tag, child, parent);
String expected = "QuickView.append('div','child','parent');";
Assert.assertEquals(call, expected);
}


@Test(groups = {"utilTests"})
public void insertAfter_2() {
public void append_2() {
QuickMockApplication app = new QuickMockApplication();
WicketTester tester = new WicketTester(app);
final QuickViewParent parent = new QuickViewParent("parent");
Expand All @@ -196,8 +196,8 @@ public QuickViewParent newParent() {
};
tester.startComponentInPage(panel);
final Item<Integer> item = (Item) quickView.get(0);
String expected = String.format("QuickView.insertAfter('%s','%s','%s');", TestQuickViewContainer.TAG_NAME, item.getMarkupId(), parent.getMarkupId());
String actual = RepeaterUtil.get().insertAfter(item, parent);
String expected = String.format("QuickView.append('%s','%s','%s');", TestQuickViewContainer.TAG_NAME, item.getMarkupId(), parent.getMarkupId());
String actual = RepeaterUtil.get().append(item, parent);
Assert.assertEquals(actual.trim(), expected.trim());
}

Expand Down

0 comments on commit 3df031c

Please sign in to comment.