Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.got5.tapestry5.jquery.utils.JQueryUtils#merge should respect recursive json objects #325

Open
donarus opened this issue Oct 2, 2013 · 0 comments

Comments

@donarus
Copy link
Contributor

donarus commented Oct 2, 2013

Hi, if someone needs to set second level jQuery property (for example properties oLanguage.oPaginate.sPrevious and oLanguage.oPaginate.sPrevious which can be used in DataTable) and uses method JQueryUtils#merge, he will ends up with
with partially rewritten options instead of merged options. JAVADoc and method name is little bit misleading

We can change method behaviour or (from backward compatibility reasons) add recursive (stack based) method with no such strict merge restrictions.

Example of ugly merging (see comments in code)

package cz.donarus.tagr.web.components.bootstrap;

import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.json.JSONObject;
import org.got5.tapestry5.jquery.utils.JQueryUtils;

@Import(library = "DataTable.js")
public class DataTable extends org.got5.tapestry5.jquery.components.DataTable {

    @Inject
    private Messages messages;

    @Override
    public JSONObject getOptions() {
        JSONObject originalPaginate = originalPaginate = new JSONObject();
        originalPaginate.put("sPrevious", messages.get("datatable.oPaginate.sPrevious"));
        originalPaginate.put("sNext", messages.get("datatable.oPaginate.sNext"));

        JSONObject originalLanguage = new JSONObject();
        originalLanguage.put("oPaginate", originalPaginate);

        /*
        FIXME: UGLY COPY PASTE FROM org.got5.tapestry5.jquery.components.DataTable, because without these lines
        call of JQueryUtils#merge in parent#setJS method will overwrite all oLanguage values by
         our returned properties (so without these lines only with pagination titles).
         */
        originalLanguage.put("sProcessing", messages.get("datatable.sProcessing"));
        originalLanguage.put("sLengthMenu", messages.get("datatable.sLengthMenu"));
        originalLanguage.put("sZeroRecords", messages.get("datatable.sZeroRecords"));
        originalLanguage.put("sEmptyTable", messages.get("datatable.sEmptyTable"));
        originalLanguage.put("sLoadingRecords", messages.get("datatable.sLoadingRecords"));
        originalLanguage.put("sInfo", messages.get("datatable.sInfo"));
        originalLanguage.put("sInfoEmpty", messages.get("datatable.sInfoEmpty"));
        originalLanguage.put("sInfoFiltered", messages.get("datatable.sInfoFiltered"));
        originalLanguage.put("sInfoPostFix", messages.get("datatable.sInfoPostFix"));
        originalLanguage.put("sSearch", messages.get("datatable.sSearch"));
        originalLanguage.put("sUrl", messages.get("datatable.sUrl"));
        /*
        FIXME: END OF UGLY COPY PASTE
         */

        JSONObject options = new JSONObject();
        options.put("oLanguage", originalLanguage);
        JQueryUtils.merge(options, super.getOptions());
        return options;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants