List of usage examples for com.google.gwt.core.client JsonUtils safeEval
public static native <T extends JavaScriptObject> T safeEval(String json) ;
From source file:fr.gael.dhus.gwt.client.page.management.ManagementDataRightPage.java
License:Open Source License
private static void getUsers(final int start, final int length, final String search, final JavaScriptObject function) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait"); GWTClient.callback(function,//from w w w . ja va2 s .c o m JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}")); userService.countForDataRight(search, new AccessDeniedRedirectionCallback<Integer>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while counting users"); } @Override public void onSuccess(final Integer total) { userService.getUsersForDataRight(start, length, search, new AccessDeniedRedirectionCallback<List<UserData>>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while searching for '" + search + "'"); } @Override public void onSuccess(List<UserData> users) { String json = "{\"aaData\": ["; for (UserData user : users) { boolean publicData = user.getUsername().startsWith("~"); json += "[{\"username\":\"" + (publicData ? user.getUsername().substring(1) : user.getUsername()) + "\", \"publicData\":" + publicData + "}," + user.getId() + "],"; } if (users.size() >= 1) { json = json.substring(0, json.length() - 1); } json += "],\"iTotalRecords\" : " + total + ", \"iTotalDisplayRecords\" : " + total + "}"; GWTClient.callback(function, JsonUtils.safeEval(json)); DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); } }); } }); }
From source file:fr.gael.dhus.gwt.client.page.management.ManagementDataRightPage.java
License:Open Source License
private static void getProducts(final int start, final int length, final String search, final JavaScriptObject function) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait"); GWTClient.callback(function,/*from w ww .j a v a 2s . c om*/ JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}")); productService.count(search, null, new AccessDeniedRedirectionCallback<Integer>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while counting products"); } @Override public void onSuccess(final Integer total) { productService.getProducts(start, length, search, null, new AccessDeniedRedirectionCallback<List<ProductData>>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while searching for '" + search + "'"); } @Override public void onSuccess(List<ProductData> products) { displayedProducts = products; boolean allChecked = true; boolean allPublic = true; boolean children = true; String json = "{\"aaData\": ["; for (ProductData product : products) { boolean checked = (selectedUser != null && selectedUser.containsProduct(product.getId())); allChecked = allChecked && checked; boolean publicProduct = (publicData != null && publicData.getId() != selectedUser.getId() && publicData.containsProduct(product.getId())) || (publicData != null && publicData.getId() == selectedUser.getId() && publicData.fromPublicCollection(product.getId())); allPublic = allPublic && publicProduct; json += "[{\"checked\":" + checked + ", \"publicData\":" + publicProduct + ", \"id\":\"" + product.getId() + "\" }, \"" + product.getIdentifier() + "\"],"; } if (total > 0) { json = json.substring(0, json.length() - 1); } else { allChecked = false; children = false; } json += "],\"iTotalRecords\" : " + total + ", \"iTotalDisplayRecords\" : " + total + "}"; GWTClient.callback(function, JsonUtils.safeEval(json)); DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); productsCheckAll = SimpleCheckBox .wrap(RootPanel.get("dr_productsCheckAll").getElement()); productsCheckAll.setValue(allChecked); productsCheckAll.setEnabled(children && state == State.EDIT && !allPublic); productsCheckAll.setTitle(allPublic ? "All products are public" : ""); } }); } }); }
From source file:fr.gael.dhus.gwt.client.page.management.ManagementDataRightPage.java
License:Open Source License
private static void getCollections(final JavaScriptObject function) { GWTClient.callback(function,//from ww w. j a v a 2s . c om JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}")); DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait"); if (root == null) { root = new CollectionData(); root.setId(null); root.setDeep(-1); } toRefresh = new ArrayList<Long>(); for (CollectionData c : displayedCollections.values()) { if (c.getDisplayedChildren() != null && c.getDisplayedChildren().size() > 0) { toRefresh.add(c.getId()); } } displayedCollections.clear(); requestCollections(root, new AccessDeniedRedirectionCallback<Void>() { @Override public void _onFailure(Throwable caught) { Window.alert("There was an error while requesting collections.\n" + caught.getMessage()); DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); } @Override public void onSuccess(Void result) { collectionsCheckAllChecked = true; collectionsAllPublic = true; String json = "{\"aaData\": ["; json += computeJSON(root); boolean children = false; if (root.getDisplayedChildren() != null && root.getDisplayedChildren().size() > 0) { json = json.substring(0, json.length() - 1); children = true; } json += "],\"iTotalRecords\" : " + (children ? 1 : 0) + ", \"iTotalDisplayRecords\" : " + (children ? 1 : 0) + "}"; GWTClient.callback(function, JsonUtils.safeEval(json)); DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); collectionsCheckAll = SimpleCheckBox.wrap(RootPanel.get("dr_collectionsCheckAll").getElement()); collectionsCheckAll.setValue(children && collectionsCheckAllChecked); collectionsCheckAll.setEnabled(children && state == State.EDIT && !collectionsAllPublic); collectionsCheckAll.setTitle(collectionsAllPublic ? "All collections are public" : ""); } }); }
From source file:fr.gael.dhus.gwt.client.page.management.ManagementEvictionPage.java
License:Open Source License
private static void getEvictableProductsFunction(final JavaScriptObject function) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait"); GWTClient.callback(function,/*from w ww . j a v a 2s.co m*/ JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}")); evictionService.getEvictableProducts(new AccessDeniedRedirectionCallback<List<ProductData>>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while accessing to evictable products.\n" + caught.getMessage()); } @Override public void onSuccess(final List<ProductData> products) { String json = toJson(GWT.getHostPageBaseURL(), products, GWTClient.getCurrentUser()); GWTClient.callback(function, JsonUtils.safeEval(json)); DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); } }); }
From source file:fr.gael.dhus.gwt.client.page.management.ManagementUsersPage.java
License:Open Source License
private static void getUsers(final int start, final int length, final String search, final JavaScriptObject function) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait"); GWTClient.callback(function,//from w ww.j ava 2 s .c o m JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}")); userService.count(search, new AccessDeniedRedirectionCallback<Integer>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while counting users"); } @Override public void onSuccess(final Integer total) { userService.getUsers(start, length, search, new AccessDeniedRedirectionCallback<List<UserData>>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while searching for '" + search + "'"); } @Override public void onSuccess(List<UserData> users) { String json = "{\"aaData\": ["; for (UserData user : users) { json += "[\"" + user.getUsername() + "\", " + user.getId() + "],"; } if (users.size() >= 1) { json = json.substring(0, json.length() - 1); } json += "],\"iTotalRecords\" : " + total + ", \"iTotalDisplayRecords\" : " + total + "}"; GWTClient.callback(function, JsonUtils.safeEval(json)); DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); } }); } }); }
From source file:fr.gael.dhus.gwt.client.page.management.ManagementUsersPage.java
License:Open Source License
private static void getRoles(final int start, final int length, final JavaScriptObject function) { boolean allChecked = true; String json = "{\"aaData\": ["; int total = RoleData.getEffectiveRoles().size(); for (RoleData r : RoleData.getEffectiveRoles()) { boolean checked = (selectedUser != null && selectedUser.containsRole(r)); allChecked = allChecked && checked; // authority.substring (5) : no 'ROLE_' prefix json += "[{\"checked\":" + checked + ", \"authority\":\"" + r.getAuthority().substring(5) + "\" }, \"" + r.toString() + "\"],"; }//w ww . ja v a 2 s . com if (total >= 1) { json = json.substring(0, json.length() - 1); } json += "],\"iTotalRecords\" : " + total + ", \"iTotalDisplayRecords\" : " + total + "}"; GWTClient.callback(function, JsonUtils.safeEval(json)); rolesCheckAll = SimpleCheckBox.wrap(RootPanel.get("rolesCheckAll").getElement()); rolesCheckAll.setValue(allChecked); boolean isNotRoot = selectedUser == null || !(selectedUser.getUsername().equals("root")); rolesCheckAll.setEnabled((state == State.EDIT && isNotRoot) || state == State.CREATE); }
From source file:fr.gael.dhus.gwt.client.page.profile.ProfileInformations.java
License:Open Source License
private static void getRoles(final int start, final int length, final JavaScriptObject function) { UserData user = GWTClient.getCurrentUser(); String json = "{\"aaData\": ["; int total = user.getRoles().size(); for (RoleData r : RoleData.getEffectiveRoles()) { if (user.containsRole(r)) { json += "[\"" + r.toString() + "\"],"; }// ww w. j av a 2 s.c o m } if (total >= 1) { json = json.substring(0, json.length() - 1); } json += "],\"iTotalRecords\" : " + total + ", \"iTotalDisplayRecords\" : " + total + "}"; GWTClient.callback(function, JsonUtils.safeEval(json)); }
From source file:fr.gael.dhus.gwt.client.page.profile.ProfileSearches.java
License:Open Source License
private static void getSearches(final int start, final int length, final JavaScriptObject function) { GWTClient.callback(function,//w w w .j av a 2 s. c om JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}")); displayedSearches.clear(); final UserData user = GWTClient.getCurrentUser(); userService.countUserSearches(user.getId(), new AccessDeniedRedirectionCallback<Integer>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while counting your saved searches."); } @Override public void onSuccess(final Integer total) { userService.scrollSearchesOfUser(start, length, user.getId(), new AccessDeniedRedirectionCallback<List<SearchData>>() { @Override public void _onFailure(Throwable caught) { Window.alert("There was an error while getting your saved searches."); } @Override public void onSuccess(List<SearchData> result) { String json = "{\"aaData\": ["; for (SearchData search : result) { String advancedText = ""; Map<String, String> advanceds = search.getAdvanced(); if (advanceds != null && !advanceds.isEmpty()) { advancedText += "<i> ("; boolean first = true; List<String> keys = new ArrayList<String>(advanceds.keySet()); Collections.sort(keys); String lastKey = ""; for (String key : keys) { if ((lastKey + "End").equals(key)) { advancedText += " to " + advanceds.get(key); } else { if (key.endsWith("End")) { advancedText += (first ? "" : ", ") + key.substring(0, key.length() - 3) + ": * to " + advanceds.get(key); } else { advancedText += (first ? "" : ", ") + key + ": " + advanceds.get(key); } } first = false; lastKey = key; } advancedText += ")</i>"; } displayedSearches.put(search.getId(), search); // json += "[\"" + search.getValue ().replace ("\"", "\\\"") + advancedText.replace ("\"", "\\\"") + "\"," + search.getId () + "," + // "{\"id\":"+search.getId ()+", \"notify\":"+search.isNotify ()+"},\"" + search.getId () + "\"],"; json += "[\"" + search.getComplete().replace("\"", "\\\"") + "\"," + search.getId() + "," + "{\"id\":" + search.getId() + ", \"notify\":" + search.isNotify() + "},\"" + search.getId() + "\"],"; } if (total >= 1) { json = json.substring(0, json.length() - 1); } json += "],\"iTotalRecords\" : " + total + ", \"iTotalDisplayRecords\" : " + total + "}"; clearSearches.getElement() .setClassName(total >= 1 ? "button_black" : "button_disabled"); GWTClient.callback(function, JsonUtils.safeEval(json)); } }); } }); }
From source file:fr.gael.dhus.gwt.client.page.profile.ProfileUploaded.java
License:Open Source License
private static void getUploadedProducts(final int start, final int length, final JavaScriptObject function) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait"); GWTClient.callback(function,/*w w w . j av a2 s . c o m*/ JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}")); final UserData user = GWTClient.getCurrentUser(); userService.countUploadedProducts(user.getId(), new AccessDeniedRedirectionCallback<Integer>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while counting your uploaded products."); } @Override public void onSuccess(final Integer total) { userService.getUploadedProductsIdentifiers(start, length, user.getId(), new AccessDeniedRedirectionCallback<List<String>>() { @Override public void _onFailure(Throwable caught) { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); Window.alert("There was an error while accessing to your uploaded products."); } @Override public void onSuccess(final List<String> products) { String json = "{\"aaData\": ["; // for (ProductData product : products) // { // Long id = product.getId (); // // String summary = ""; // for (int i = 0; i < product.getSummary ().size (); i++) // { // summary = summary + product.getSummary ().get (i) + (i == product.getSummary ().size ()-1 ?"":", "); // } // // String download = "\""+GWT.getHostPageBaseURL ()+"odata/product("+id+")/"+"Download\""; // // json += "["+(product.hasThumbnail () ? "\""+GWT.getHostPageBaseURL ()+"odata/product("+id+")/"+"\"" : null) // +",{\"identifier\": \""+product.getIdentifier ()+ // "\", \"link\": \""+GWT.getHostPageBaseURL ()+"odata/product("+id+")/\", \"summary\": \""+ // summary+"\"},"+id+","+download+","+id+"],"; // } // if (products.size () >= 1) // { // json = json.substring (0, json.length ()-1); // } // json += "],\"iTotalRecords\" : "+total+", \"iTotalDisplayRecords\" : "+total+"}"; for (String product : products) { json += "[\"" + product + "\"],"; } if (products.size() >= 1) { json = json.substring(0, json.length() - 1); } json += "],\"iTotalRecords\" : " + total + ", \"iTotalDisplayRecords\" : " + total + "}"; GWTClient.callback(function, JsonUtils.safeEval(json)); DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); } }); } }); }
From source file:fr.gael.dhus.gwt.client.page.SearchPage.java
License:Open Source License
private static void reloadSavedSearches() { userService.getAllUserSearches(GWTClient.getCurrentUser().getId(), new AccessDeniedRedirectionCallback<List<SearchData>>() { @Override/*from ww w. j a va 2 s . c o m*/ public void _onFailure(Throwable caught) { Window.alert("There was an error while getting your saved searches."); } @Override public void onSuccess(List<SearchData> result) { if (result == null) { return; } String searches = "["; for (SearchData search : result) { String advancedText = ""; Map<String, String> advanceds = search.getAdvanced(); if (advanceds != null && !advanceds.isEmpty()) { advancedText += "<i> ("; boolean first = true; List<String> keys = new ArrayList<String>(advanceds.keySet()); Collections.sort(keys); String lastKey = ""; for (String key : keys) { if ((lastKey + "End").equals(key)) { advancedText += " to " + advanceds.get(key); } else { if (key.endsWith("End")) { advancedText += (first ? "" : ", ") + key.substring(0, key.length() - 3) + ": * to " + advanceds.get(key); } else { advancedText += (first ? "" : ", ") + key + ": " + advanceds.get(key); } } first = false; lastKey = key; } advancedText += ")</i>"; } displayedSearches.put(search.getId(), search); searches += "{\"id\":" + search.getId() + ",\"value\":\"" + search.getComplete().replace("\"", "\\\"") + "\"},"; } if (result.size() > 0) { searches = searches.substring(0, searches.length() - 1); } searches += "]"; setSearches(JsonUtils.safeEval(searches)); } }); }