Commits

Juan Carlos Picado Herrera committed 9a97058

js bugfixes
Done ENCUESTAME-591

Comments (0)

Files changed (5)

enme-js/resources-enme-war/src/main/resources/resource/js/me/web/widget/tweetpoll/HashTagsItem.js

                              _WidgetsInTemplateMixin], {
 
           // template string.
-            templateString : template,
+          templateString : template,
 
           /***
           * the body of hashtag.

enme-js/resources-enme-war/src/main/resources/resource/js/me/web/widget/tweetpoll/HashTagsSuggest.js

+/*
+ * Copyright 2013 encuestame
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/***
+ *  @author juanpicado19D0Tgm@ilDOTcom
+ *  @version 1.146
+ *  @module TweetPoll
+ *  @namespace Widget
+ *  @class HashtagSuggest
+ */
 define([
          "dojo/_base/declare",
          "dijit/_WidgetBase",
          "dijit/_TemplatedMixin",
          "dijit/_WidgetsInTemplateMixin",
+         "dijit/form/TextBox",
          "me/core/main_widgets/EnmeMainLayoutWidget",
          "me/web/widget/suggestion/Suggest",
          "me/core/enme",
                 _WidgetBase,
                 _TemplatedMixin,
                 _WidgetsInTemplateMixin,
+                TextBox,
                 main_widget,
                 Suggest,
                 _ENME,
                  template) {
-            return declare([ _WidgetBase, _TemplatedMixin, main_widget, Suggest, _WidgetsInTemplateMixin], {
+            return declare([ _WidgetBase,
+                             _TemplatedMixin,
+                             main_widget,
+                             Suggest,
+                             _WidgetsInTemplateMixin], {
+
+           // template string.
+           templateString : template,
 
-          // template string.
-            templateString : template,
+           /***
+            * Post create cycle life.
+            */
+           postCreate : function() {
+                var myTextBox = new TextBox({
+                    name: "suggest_" + this.id,
+                    value: "",
+                    placeHolder: ''
+                });
+                this._suggest.appendChild(myTextBox.domNode);
+           },
 
           /*
            *

enme-js/resources-enme-war/src/main/resources/resource/js/me/web/widget/tweetpoll/templates/suggest.html

         <div>
           <input type="text"
                  data-dojo-attach-point="_suggest"
-                 dojoType="dijit.form.TextBox"
-                 maxLength="25"
-                 trim="true"
                  class="littleInputClass">
           </input>
         </div>

enme-utils/src/main/java/org/encuestame/utils/RestFullUtil.java

 import java.util.regex.Pattern;
 
 /**
- * Test for {@link PictureUtils}.
+ * RESTFul utilities.
  * @author Picado, Juan juanATencuestame.org
- * @since
  */
 public class RestFullUtil {
 
     private static final Pattern WHITESPACE = Pattern.compile("[\\s]");
 
     /**
-     *
+     * Apply the correct format on a hastag.
      */
-    public static String formatHasgTag(String hashTag){
+    public static String formatHasgTag(String hashTag) {
         if (hashTag != null) {
             hashTag = hashTag.toLowerCase();
         } else {
     }
 
     /**
-     *
+     * Slugify a string
      * @param input
-     * @return
+     * @return slug string
      * @throws UnsupportedEncodingException
      */
     public static String slugify(final String input) {
             return "";
         }
         String toReturn = RestFullUtil.normalize(input);
+        toReturn = toReturn.replaceAll("[^a-zA-Z]", " ");
+        toReturn = toReturn.replaceAll("\\s+", " ").trim().toLowerCase();
         toReturn = toReturn.replace(" ", "-");
-        toReturn = toReturn.toLowerCase();
         toReturn = RestFullUtil.encodeUTF8(toReturn);
         return toReturn;
     }
 
     /**
-     *
+     * Encode a string with UTF-8.
      * @param toReturn
      * @return
      */
       }
 
     /**
-     *
+     * Normalize a string
      * @param input
      * @return
      */
-    private static String normalize(String input) {
+    private static String normalize(final String input) {
         if (input == null || input.length() == 0) return "";
         return Normalizer.normalize(input, Form.NFD).replaceAll("[^\\p{ASCII}]","");
     }

enme-utils/src/test/java/org/encuestame/utils/TestSlug.java

+package org.encuestame.utils;
+
+import junit.framework.Assert;
+
+import org.encuestame.utils.categories.test.DefaultTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(DefaultTest.class)
+public class TestSlug extends AbstractBaseUtils{
+
+    /**
+     * Slug test.
+     */
+    @Test
+    public void testSlugs() {
+           // test 1
+           final String value1 = "___ +++ \" ????? ##@!#@!$#@ dsdsa ds$#@$#@a dsa dsa dsa$#$#@dsads  321321DS EDWRe432SFDS#!@#@!#@!E#SA ,.,.,. ..   .. ";
+           final String restult1 = RestFullUtil.slugify(value1);
+           Assert.assertEquals(restult1, "dsdsa-ds-a-dsa-dsa-dsa-dsads-ds-edwre-sfds-e-sa");
+           //
+           final String value2 = "Who was the first woman to drive in the Indy 500?";
+           final String restult2 = RestFullUtil.slugify(value2);
+           Assert.assertEquals(restult2, "who-was-the-first-woman-to-drive-in-the-indy");
+           //
+           final String value3 = "Where did the Chevrolet Corvette get its name?";
+           final String restult3 = RestFullUtil.slugify(value3);
+           Assert.assertEquals(restult3, "where-did-the-chevrolet-corvette-get-its-name");
+           //
+           final String value4 = "What color was Luke's lightsaber in the first Star Wars film? ";
+           final String restult4 = RestFullUtil.slugify(value4);
+           Assert.assertEquals(restult4, "what-color-was-luke-s-lightsaber-in-the-first-star-wars-film");
+           //
+           final String value5 = "Is @japita your twitter nickname?";
+           final String restult5 = RestFullUtil.slugify(value5);
+           Assert.assertEquals(restult5, "is-japita-your-twitter-nickname");
+           //
+           final String value6 = "Are you fan of the 20 of 50 twenty fox?";
+           final String restult6 = RestFullUtil.slugify(value6);
+           Assert.assertEquals(restult6, "are-you-fan-of-the-of-twenty-fox");
+    }
+}