Commits

Juan Carlos Picado Herrera  committed d926173

Fixed tweet poll issues, hashtag remove and keyboard support.

  • Participants
  • Parent commits 4113fc8

Comments (0)

Files changed (5)

File enme-war/src/main/webapp/resource/css-compile/shared-components/suggest.css

   padding: 2px;
 }
 
-.suggest .wrapper-suggest .suggestBox .suggesItem:hover{
+.suggest .wrapper-suggest .suggestBox .suggesItem:hover, .suggest-selected {
     background-color: #939397;
     color: #FFF;
 }

File enme-war/src/main/webapp/resource/js/me/web/widget/suggestion/Suggest.js

          *
          * @property
          */
-        _delay : 700,
+        _delay : 50,
 
         /**
          *
                             parent._inProcessKey = false;
                             if (dojo.keys.SPACE == e.keyCode || dojo.keys.ENTER == e.keyCode) {
                                 parent.processSpaceAction();
+                            } else if (dojo.keys.ESCAPE == e.keyCode) {
+                                parent.hide();
                             } else if (dojo.keys.UP_ARROW == e.keyCode) {
                                 //TODO: down by suggestion list.
                                 parent.moveBetweenItems(-1);
          * @param
          */
         moveBetweenItems : function (flag) {
-            var isAnySelected = true;
-            dojo.forEach(this._temp_suggestion_items, dojo.hitch(this, function(entry, i) {
-                // move to  up
+            // create a selected item after keyboard select
+            var isAnySelected = true,
+            parent = this,
+            t_length = this._temp_suggestion_items.length,
+            create_item = function(id, hashTagName) {
+                 return {
+                        data: { id : id,
+                                label : hashTagName
+                              },
+                        parentWidget : parent
+                        };
+            };
+            for (var i = 0; i < t_length; i++) {
+                var entry = parent._temp_suggestion_items[i];
                 if( entry.isSelected()) {
                     isAnySelected = false;
                     entry.unSelect();
-                    var next_item = this._temp_suggestion_items[i + flag];
-                    next_item.selected();
-                    return false;
+                    if (t_length -1  === i) { // is the last one
+                        var next_item;
+                        if (flag < 0 ) { // up -1
+                            next_item = parent._temp_suggestion_items[t_length - 2];
+                        } else { // down +1
+                            next_item = parent._temp_suggestion_items[0];
+                        }
+                        if (next_item) {
+                            next_item.selected();
+                        }
+                        parent.selectedItem = create_item(next_item.data.id, next_item.data.label);
+                        return true;
+                    } else if ( i === 0 && flag < 0) {
+                        next_item = parent._temp_suggestion_items[t_length - 1];
+                        if (next_item) {
+                            next_item.selected();
+                        }
+                        parent.selectedItem = create_item(next_item.data.id, next_item.data.label);
+                        return true;
+                    } else {
+                        var next_item = parent._temp_suggestion_items[i + flag];
+                        if (next_item) {
+                            next_item.selected();
+                        }
+                        parent.selectedItem = create_item(next_item.data.id, next_item.data.label);
+                        return true;
+                    }
                 }
-            }));
-
-            if (isAnySelected)
-            this._temp_suggestion_items[flag ? 0 : this._temp_suggestion_items.length - 1].selected();
+            }
+            if (isAnySelected) {
+                var entry;
+                if (flag < 0) {
+                    entry = this._temp_suggestion_items[t_length - 1];
+                    entry.selected();
+                } else {
+                    entry = this._temp_suggestion_items[0];
+                    entry.selected();
+                }
+                parent.selectedItem = create_item(entry.data.id, entry.data.label);
+            }
         },
 
        /**
         processSelectedItemButton : function() {
             if (this.textBoxWidget && this.addButton) {
                 this.hide();
-                var newValue = {id:null, label:"", newValue: true};
+                var newValue = {
+                    id : null,
+                    label: "",
+                    newValue: true
+                };
                 newValue.label = this.textBoxWidget.get("value");
                 this.selectedItem = newValue;
-                if (!encuestame.utilities.isEmpty(newValue.label)) {
+                if (!_ENME.isEmpty(newValue.label)) {
                     this.processSelectedItem(this.selectedItem);
                 }
                 this.clear();
 
         //Process Selected Item.
         processSelectedItem : function(selectedItem){
-            console.info("implemt this method in the parent widget 2", selectedItem);
+            _ENME.log("implemt this method in the parent widget 2", selectedItem);
         }
   });
 });

File enme-war/src/main/webapp/resource/js/me/web/widget/suggestion/SuggestItem.js

         */
         _selectItem: function(event) {
             dojo.stopEvent(event);
-            this._selected = !this._selected;
+            this._selected = false;
             this.parentWidget.selectedItem = this.data;
             this.parentWidget.hide();
             this.processItem(this.data);

File enme-war/src/main/webapp/resource/js/me/web/widget/tweetpoll/HashTags.js

            postCreate: function() {
                //create new hashtahg suggest.
                var hashTagWidget = new HashTagsSuggest({label: this._hashtahButtonLabel});
-                //the action after push "add" button.
+
+                // the action after push "add" button.
                 hashTagWidget.processSelectedItemButton = dojo.hitch(this, function() {
                     if (hashTagWidget.textBoxWidget && hashTagWidget.addButton) {
                         var newValue = {id : null, label :"" , newValue : true};
                 //the action if user push on space bar.
                 hashTagWidget.processSpaceAction =  dojo.hitch(this, function() {
                     if (hashTagWidget.textBoxWidget) {
-                        var currentText = dojo.trim(hashTagWidget.textBoxWidget.get("value"));
-                        var added = false;
-                        if (hashTagWidget._itemStored.length > 0) {
-                            dojo.forEach(
-                                hashTagWidget._itemStored,
-                                dojo.hitch(this, function(data, index) {
-                                    if (!added) {
-                                        if (currentText.toLowerCase() == data.i.hashTagName.toLowerCase()){
-                                            //console.debug("adding existing item", data.i);
-                                            hashTagWidget.processSelectedItem({id:data.i.id, label:data.i.hashTagName, newValue: false});
-                                            hashTagWidget.hide();
-                                            added = true;
-                                        } else { // TODO: this loop is invalid, always is "else" after first loop, works because
-                                                 //  the unique results always === 1
-                                           // console.debug("adding existing NEW item",{id:null, label:currentText, newValue: true} );
-                                           if (currentText != '') {
-                                             hashTagWidget.processSelectedItem({id:null, label:currentText, newValue: true});
-                                             hashTagWidget.hide();
-                                             added = true;
-                                           }
-                                        }
-                                   }
-                                }));
+                        // check if the selected item (object saved if user select with the mouse or the keyboard) exist
+                        if (typeof hashTagWidget.selectedItem === 'undefined' || hashTagWidget.selectedItem === null) {
+                            var currentText = dojo.trim(hashTagWidget.textBoxWidget.get("value"));
+                            var added = false;
+                            if (hashTagWidget._itemStored.length > 0) {
+                                dojo.forEach(
+                                    hashTagWidget._itemStored,
+                                    dojo.hitch(this, function(data, index) {
+                                        if (!added) {
+                                            if (currentText.toLowerCase() == data.i.hashTagName.toLowerCase()){
+                                                //console.debug("adding existing item", data.i);
+                                                hashTagWidget.processSelectedItem({id:data.i.id, label:data.i.hashTagName, newValue: false});
+                                                hashTagWidget.hide();
+                                                added = true;
+                                            } else { // TODO: this loop is invalid, always is "else" after first loop, works because
+                                                     //  the unique results always === 1
+                                               // console.debug("adding existing NEW item",{id:null, label:currentText, newValue: true} );
+                                               if (currentText != '') {
+                                                 hashTagWidget.processSelectedItem({id:null, label:currentText, newValue: true});
+                                                 hashTagWidget.hide();
+                                                 added = true;
+                                               }
+                                            }
+                                       }
+                                    }));
+                             } else {
+                                 hashTagWidget.processSelectedItem({id:null, label: currentText, newValue: true});
+                                 hashTagWidget.hide();
+                             }
                          } else {
-                             hashTagWidget.processSelectedItem({id:null, label: currentText, newValue: true});
-                             hashTagWidget.hide();
+                            var _selected_item = hashTagWidget.selectedItem.data;
+                            _selected_item .newValue = false;
+                            hashTagWidget.processSelectedItem(_selected_item);
+                            hashTagWidget.hide();
                          }
                       //console.debug(hashTagWidget._itemStored);
                     }
            }
 
     });
-});
-
-//dojo.provide("encuestame.org.core.commons.tweetPoll.HashTags");
-//
-//dojo.require("dijit.form.Form");
-//dojo.require("dijit.Dialog");
-//dojo.require('encuestame.org.core.commons');
-//dojo.require("encuestame.org.core.shared.utils.Suggest");
-//dojo.require("encuestame.org.main.EnmeMainLayoutWidget");
-//dojo.require("encuestame.org.core.commons.tweetPoll.TweetPollCore");
-//
-//dojo.declare(
-//    "encuestame.org.core.commons.tweetPoll.HashTags",
-//    [encuestame.org.main.EnmeMainLayoutWidget, encuestame.org.core.commons.tweetPoll.TweetPollCore],{
-//
-//        /**
-//         * template.
-//         */
-//        templatePath: dojo.moduleUrl("encuestame.org.core.commons.tweetPoll", "templates/hashtag.html"),
-//
-
-//    }
-//);
-//
-///***
-// * HashTag Item.
-// */
-//dojo.declare(
-//        "encuestame.org.core.commons.tweetPoll.HashTagsItem",
-//        [encuestame.org.main.EnmeMainLayoutWidget],{
-//        //template
-//        templatePath: dojo.moduleUrl("encuestame.org.core.commons.tweetPoll", "templates/hashtagItem.html"),
-//        //widgets in template
-//        wigetsInTemplate: true,
-//
-//        /***
-//         * the body of hashtag.
-//         */
-//        data : null,
-//
-//        /***
-//         * the label of the hashtag.
-//         */
-//        label : null,
-//
-//        /***
-//         * Parent widget reference.
-//         */
-//        parentWidget : null,
-//
-//        /***
-//         *
-//         */
-//        postCreate : function() {
-//            //console.debug("new HashTag", this.label);
-//        },
-//
-//        /***
-//         *
-//         * @param event
-//         */
-//        _options : function(event){
-//            var dialog = this.parentWidget.getDialog();
-//            dialog.item = this;
-//            dialog.show();
-//        }
-//});
-//
-//
-//dojo.declare(
-//    "encuestame.org.core.commons.tweetPoll.HashTagsSuggest",
-//    [encuestame.org.core.shared.utils.Suggest],{
-//
-//    	/***
-//    	 * Template.
-//    	 */
-//        templatePath: dojo.moduleUrl("encuestame.org.core.commons.tweetPoll", "templates/suggest.html"),
-//
-//        block : function(){
-//        },
-//
-//        unblock : function(){
-//        }
-//});
+});

File enme-war/src/main/webapp/resource/js/me/web/widget/tweetpoll/templates/hashtag.html

     </div>
     <div data-dojo-type="dijit/Dialog" id="option_${id}" title="Options" style="width: 400px;">
              <div class="web-generic-dialog-content">
+                 <span>
+                   <h3>
+                      Are you sure?
+                   </h3>
+               </span>
                  <div class="button">
                        <span class="optionItem">
-                           <button data-dojo-type="dijit/form/Button" data-dojo-attach-event="onclick:_removeItem">
+                           <button data-dojo-type="dijit/form/Button" data-dojo-attach-event="onClick:_removeItem">
                                Remove
                            </button>
                        </span>