public List<Asset> getJavaScriptLibraries() {
    String jQueryUIPath = symbolSource.valueForSymbol(JQuerySymbolConstants.JQUERY_UI_PATH);
    if (!jQueryUIPath.endsWith("/")) {

      jQueryUIPath += "/";
    }

    final List<Asset> javaScriptStack = new ArrayList<Asset>();

    javaScriptStack.add(
        assetSource.getClasspathAsset(
            String.format(
                "%s%s/jquery.ui.datepicker%s.js",
                jQueryUIPath,
                (!productionMode ? "/minified" : ""),
                (!productionMode ? ".min" : ""))));

    final Asset datePickerI18nAsset = getLocaleAsset(threadLocale.getLocale(), jQueryUIPath);

    if (datePickerI18nAsset != null) {
      javaScriptStack.add(datePickerI18nAsset);
    }

    javaScriptStack.add(
        assetSource.getExpandedAsset("${assets.path}/components/datefield/datefield.js"));

    return javaScriptStack;
  }
  public String getInitialization() {
    Locale locale = threadLocale.getLocale();

    JSONObject spec = new JSONObject();

    DateFormatSymbols symbols = new DateFormatSymbols(locale);

    spec.put("months", new JSONArray((Object[]) symbols.getMonths()));

    StringBuilder days = new StringBuilder();

    String[] weekdays = symbols.getWeekdays();

    Calendar c = Calendar.getInstance(locale);

    int firstDay = c.getFirstDayOfWeek();

    // DatePicker needs them in order from monday to sunday.

    for (int i = Calendar.MONDAY; i <= Calendar.SATURDAY; i++) {
      days.append(weekdays[i].substring(0, 1));
    }

    days.append(weekdays[Calendar.SUNDAY].substring(0, 1));

    spec.put("days", days.toString().toLowerCase(locale));

    // jQuery DatePicker widget expects 0 to be sunday. Calendar defines SUNDAY as 1, MONDAY as 2,
    // etc.
    spec.put("firstDay", firstDay - 1);

    // set language
    spec.put("language", locale.getLanguage());

    // TODO: Skip localization if locale is English?

    return String.format("Tapestry.DateField.initLocalization(%s);", spec.toString(compactJSON));
  }
示例#3
0
 private Locale defaulted(Locale locale) {
   return locale != null ? locale : threadLocale.getLocale();
 }