1. Juan Carlos Picado Herrera
  2. encuestame

Commits

Juan Carlos Picado Herrera  committed 95fb1f8

Customized html5 DnD for poll answers

  • Participants
  • Parent commits 4500c52
  • Branches master

Comments (0)

Files changed (19)

File enme-business/src/main/java/org/encuestame/business/service/PollService.java

View file
  • Ignore whitespace
         return poll;
     }
 
-	/*
-	 * (non-Javadoc)
-	 *
-	 * @see
-	 * org.encuestame.core.service.imp.IPollService#getPollByAnswerId(java.lang
-	 * .Long, java.lang.Long,
-	 * org.encuestame.persistence.domain.security.UserAccount)
-	 */
-	public Poll getPollByAnswerId(final Long pollId, final Long answerId,
-			final UserAccount account) throws EnMeNoResultsFoundException {
-		final Poll poll = this.getPollById(pollId);
-		QuestionAnswer qA = getQuestionDao().retrieveAnswersByQuestionId(
-				poll.getQuestion(), answerId);
-		if (qA == null) {
-			throw new EnMeNoResultsFoundException("Answer not found");
-		}
-		return poll;
-	}
+    /*
+     * (non-Javadoc)
+     *
+     * @see
+     * org.encuestame.core.service.imp.IPollService#getPollByAnswerId(java.lang
+     * .Long, java.lang.Long,
+     * org.encuestame.persistence.domain.security.UserAccount)
+     */
+    public Poll getPollByAnswerId(final Long pollId, final Long answerId,
+            final UserAccount account) throws EnMeNoResultsFoundException {
+        final Poll poll = this.getPollById(pollId);
+        QuestionAnswer qA = getQuestionDao().retrieveAnswersByQuestionId(
+                poll.getQuestion(), answerId);
+        if (qA == null) {
+            throw new EnMeNoResultsFoundException("Answer not found");
+        }
+        return poll;
+    }
 
     /**
      * Retrieve a {@link Poll} based on id.
         log.debug("poll getResultVotes " + poll);
         final List<PollBeanResult> results = new ArrayList<PollBeanResult>();
         final List<Object[]> list = getPollDao().retrieveResultPolls(poll.getPollId(), poll.getQuestion().getQid());
-        //log.debug("retrieveResultPolls==> "+list.size());
+        log.debug("retrieveResultPolls==> "+list.size());
         for (Object[] objects : list) {
             final Long answerId = objects[0] == null ? null : Long.valueOf(objects[0].toString());
             final String answerString = objects[1] == null ? null : objects[1].toString();

File enme-war/src/main/webapp/WEB-INF/layouts/standard/page.jsp

View file
  • Ignore whitespace
             </div>
         </c:if>
         <tiles:insertAttribute name="content" />
-            <c:if test="${logged}">
-            <!--
-               <div dojoType="encuestame.org.core.shared.utils.Toaster" duration="<%=EnMePlaceHolderConfigurer.getProperty("not.toaster.duration")%>"
-                     messageTopic="/encuestame/message/publish"
-                     positionDirection="<%=EnMePlaceHolderConfigurer.getProperty("not.toaster.position")%>"
-                     id="toasted_message">
-              </div>
-            -->
-                    </c:if>
       </div>
       <footer id="footer">
         <tiles:insertAttribute name="footer" />

File enme-war/src/main/webapp/resource/css-compile/common.css

View file
  • Ignore whitespace
     user-select: none;
 }
 
+.enme-dnd [draggable] {
+  -moz-user-select: none;
+  -khtml-user-select: none;
+  -webkit-user-select: none;
+  user-select: none;
+}
+
 a.point {
   cursor: pointer;
   text-decoration: none;

File enme-war/src/main/webapp/resource/css-compile/dojo-fixes.css

View file
  • Ignore whitespace
 #enme-content input, textarea, select .dijitInputField{
-  width: 16px;
+  /*width: 16px;*/
 }
 
 #enme-content .dijitInputField input:focus {

File enme-war/src/main/webapp/resource/css-compile/input.css

View file
  • Ignore whitespace
 }
 
 #enme-content input[type="text"], input[type="password"] {
-    font-size : 13px
+    /*font-size : 13px*/
 }
 
 /** placeholder text **/
 }
 #enme-content input, textarea, select {
     display: inline-block;
-    width: 210px;
+  /*  width: 210px;*/
     padding: 4px;
     margin: 0;
     outline: 0;

File enme-war/src/main/webapp/resource/css-compile/web/components/admon-list-rows.css

View file
  • Ignore whitespace
 
 .web-item-row .web-item-row-section-title>div {
     clear: both;
-    color: #4D4C4C;
-    font-size: 14px;
+    color: #222;
     position: relative;
 }
 

File enme-war/src/main/webapp/resource/css-compile/web/components/poll-create.css

View file
  • Ignore whitespace
 /** poll */
-div.web-poll-wrapper {
+.web-poll-wrapper {
     padding: 10px;
     margin: 0 auto;
     padding: 35px 0;
     width: auto;
 }
 
-div.web-poll-wrapper .web-poll-question {
+.web-poll-wrapper .web-poll-question {
 
 }
 
-div.web-poll-wrapper .web-poll-question .web-question .dijitTextBox {
+.web-poll-wrapper .web-poll-question .web-question .dijitTextBox {
     font-size: 130%;
     padding: 3px;
     width: 610px;
 /*   box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset, 0 0 8px rgba(82, 168, 236, 0.6); */
 /*   outline: 0 none; */
 /* } */
-div.web-poll-wrapper .web-poll-question .web-question {
+.web-poll-wrapper .web-poll-question .web-question {
     float: left;
     width: 100px;
 }
 
-div.web-poll-wrapper .web-poll-question-folder {
+.web-poll-wrapper .web-poll-question-folder {
     float: right;
     left: 0;
     margin-right: 35px;
     position: relative;
 }
 
-div.web-poll-wrapper ul.web-poll-answers {
+.web-poll-wrapper ul.web-poll-answers {
 
 }
 
-div.web-poll-wrapper ul.web-poll-answers li {
+.web-poll-wrapper ul.web-poll-answers li {
     list-style: none;
     padding: 5px;
 }
 
-.web-poll-question .web-tweetpoll-section {
-    width: auto;
-    margin: auto 0;
+.web-poll-question .web-poll-section .space {
+  overflow: auto;
+  padding: 20px 10px;
 }
 
-.web-poll-question .web-poll-section {
-  background-color: #F6F6F6;
-  border: 1px solid #E5E5E5;
-  border-radius: 10px 10px 10px 10px;
-  z-index: 5;
+.web-poll-wrapper .web-poll-question .web-question .dijitInputField {
+    padding: 0px;
 }
 
-.web-poll-question .web-poll-section .space {
-  overflow: auto;
-  padding: 10px;
+.web-poll-wrapper .web-poll-question .web-question .dijitInputField  > input, .web-poll-answers .dijitInputField  > input{
+    font-size: 13px;
+    padding: 5px;
+}
+
+.web-poll-wrapper .dijitPlaceHolder {
+  font-size: 12px;
+  line-height: 20px;
+}
+
+.web-poll-question .web-poll-section .section-option-wrapper .section-default  > div {
+    padding : 5px;
+}
+
+.web-poll-question .web-poll-section .section-option-wrapper .dijitSpinner .dijitSpinnerButtonInner {
+  width: 13px;
+}
+
+.web-poll-question .web-poll-section .section-option-wrapper .section-default .dijitTextBox, .web-poll-wrapper .web-poll-question .web-question .dijitTextBox {
+  border-radius: 0px !important;
+}
+
+.dijitValidationContainer > input {
+    width: 15px;
+}
+
+.repeated-votes .section, .date-to-close .section {
+    padding: 5px 0;
+    margin-top: 1px;
 }
 
-.web-poll-question .web-poll-section div.web-poll-section-title {
-  border-radius: 10px 10px 0 0;
-  color: #FFFFFF;
-  font-size: 110%;
-  font-weight: bold;
-  padding: 10px;
+.botton-button-publish {
+  margin-top: 5px;
 }

File enme-war/src/main/webapp/resource/css-compile/web/components/tweetpoll-create.css

View file
  • Ignore whitespace
 
 div.spaceBlock {}
 
-div.web-tweetpoll-section {
+div.web-tweetpoll-section, .web-poll-question .web-tweetpoll-section  {
     background-color: white;
     border: 1px solid #E5E5E5;
     margin: 0 auto;
 
 }
 
-div.web-tweetpoll-section div.web-tweetpoll-section-title {
+div.web-tweetpoll-section div.web-tweetpoll-section-title, .web-poll-question .web-poll-section div.web-poll-section-title {
     /** #737373 D7D7D7 #8EA5B7  */
     color: white;
     font-size: 15px;

File enme-war/src/main/webapp/resource/css-compile/web/default.css

View file
  • Ignore whitespace
 }
 
 .enme-text .dijitTextBox .dijitInputField {
-  font-size: 13px;
   padding: 1px 2px;
 }
 
 .enme-text-large .dijitTextBox {
   border-radius: 7px 7px 7px 7px;
   padding: 2px;
-  width: 250px;
+  /*width: 250px;*/
 }
 
 .enme-text-large .dijitTextBox .dijitInputContainer {

File enme-war/src/main/webapp/resource/css-compile/web/public.css

View file
  • Ignore whitespace
 
 }
 
+li.over {
+    border: 2px dashed #000;
+}
+
+.me_opa {
+    opacity: 0.5
+}
+
+.all_opa {
+    opacity: 1
+}
+
 .single-response .single-response-handle {
     float: left;
     margin-right: 10px;

File enme-war/src/main/webapp/resource/js/me/web/widget/poll/Poll.js

View file
  • Ignore whitespace
+/*
+ * 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 Poll
+ *  @namespace Widget
+ *  @class Poll
+ */
 define([
          "dojo/_base/declare",
+         "dojo/dom-attr",
          "dijit/_WidgetBase",
          "dijit/_TemplatedMixin",
          "dijit/_WidgetsInTemplateMixin",
          "dojo/text!me/web/widget/poll/templates/poll.html" ],
         function(
                 declare,
+                domAttr,
                 _WidgetBase,
                 _TemplatedMixin,
                 _WidgetsInTemplateMixin,
            *
            */
           postCreate : function() {
+              var parent = this;
               this._folderWidget = new FolderSelect({folderContext : "poll"});
               this._questionWidget = new Question(
                       {
               if (this._folder) {
                   this._folder.appendChild(this._folderWidget.domNode);
               }
-              this.enableDndSupport(this._source, true);
               //add default answers.
+              var dnd_sources = [];
               for (var i= 0; i <= this._default_answers; i++) {
-                   var li = this._newAnswer({ dndEnabled : true});
+                   var li = this._newAnswer({ dndEnabled : false});
                    this.addItem(li);
+                   if (parent.isDnD) {
+                       dnd_sources.push(li);
+                   }
+              }
+
+              if (parent.isDnD) {
+                  var dragSrcEl = null;
+                  this.enableDnDSupport(dnd_sources,
+                    {
+                      dragstart : function (e) {
+                        var node = this;
+                        //this.style.opacity = '0.4';
+                        dojo.addClass(this, "me_opa");
+                        dragSrcEl = this;
+                        console.log("iniciando drag", dragSrcEl);
+                        e.dataTransfer.effectAllowed = 'move';
+                        e.dataTransfer.setData('poll-answer', domAttr.get(node, 'd-id'));
+                      },
+                      dragenter : function (e) {
+                        // this / e.target is the current hover target.
+                        var node = this;
+                        //console.log('drag dragenter', node, e.target);
+                        this.classList.add('over');
+                      },
+                      dragover : function (e) {
+                        if (e.preventDefault) {
+                            e.preventDefault(); // Necessary. Allows us to drop.
+                        }
+                        e.dataTransfer.dropEffect = 'move';  // See the section on the DataTransfer object.
+                        return false;
+                      },
+                      dragleave : function (e) {
+                        var node = this;
+                        //console.log('drag dragleave', node, e.target);
+                       this.classList.remove('over');  // this / e.target is previous target element.
+                      },
+                      drop : function (e) {
+                        var node = this;
+                        //dragSrcEl = this.innerHTML;
+                        var origin_id  = e.dataTransfer.getData('poll-answer');
+                        var target_id = domAttr.get(node, 'd-id');
+                        var _w = registry.byId(origin_id);
+                        var _w_t = registry.byId(target_id);
+                        //var idelt = ev.dataTransfer.getData("poll-answer");
+                        console.log('DROPEDDD', _w.domNode, _w_t.domNode);
+                        console.log("this target node", node);
+                        console.log("this source node", dragSrcEl);
+                        node.appendChild(_w.domNode);
+                        domAttr.set(node, 'd-id', _w.id);
+                        dragSrcEl.appendChild(_w_t.domNode);
+                        domAttr.set(dragSrcEl, 'd-id', _w_t.id);
+                        //ev.target.appendChild(document.getElementById(idelt));
+                        // return false so the event will not be propagated to the browser
+                        // this / e.target is current target element.
+                        if (e.stopPropagation) {
+                          e.stopPropagation(); // stops the browser from redirecting.
+                        }
+                        e.dataTransfer.clearData("poll-answer");
+                        // See the section on the DataTransfer object.
+                        return false;
+                      },
+                      dragend : function (e) {
+                        var node = this;
+                        //this.style.opacity = '1';
+                        console.log('DROP ENDDDD', node);
+                         [].forEach.call(dnd_sources, function (col) {
+                            //console.info("---> col ",col);
+                            //col.classList.remove('over');
+                            dojo.removeClass(col, "me_opa");
+                            //this.style.opacity = '1';
+                         });
+
+                      }
+                    });
+              } else {
+                //TODO: remove icons to drag
               }
+
+
               // trigger the validate poll or publish and create
               dojo.connect(this._publish, "onClick", dojo.hitch(this, this._validatePoll));
               // trigger the add new answer
 
           /**
            *
+           * @method
+           */
+          addItem : function (node) {
+            this._source.appendChild(node);
+          },
+
+          /**
+           *
            * @param event
            */
           _addAnswer : function(event) {
            */
           _newAnswer : function(params){
               params = params == null ? {} : params;
-              var li = dojo.create("li");
-              dojo.addClass(li, "dojoDndItem");
               var answer = new SingleResponse(params);
+              var li = dojo.create("li");
+              //dojo.addClass(li, "dojoDndItem");
+              //draggable="true"
+              domAttr.set(li, 'draggable', true);
+              domAttr.set(li, 'd-id', answer.id);
               this._answer_widget_array.push(answer);
               li.appendChild(answer.domNode);
               //console.info("_newAnswer", li);

File enme-war/src/main/webapp/resource/js/me/web/widget/poll/PollNavigate.js

View file
  • Ignore whitespace
             detail_manage_published : _ENME.getMessage("detail_manage_published"),
             detail_manage_unpublished : _ENME.getMessage("detail_manage_unpublished"),
             detail_manage_only_completed : _ENME.getMessage("detail_manage_only_completed"),
-
             detail_manage_poll_title : _ENME.getMessage("detail_manage_poll_title"),
             detail_manage_filters : _ENME.getMessage("detail_manage_filters"),
             detail_manage_filters : _ENME.getMessage("detail_manage_filters"),

File enme-war/src/main/webapp/resource/js/me/web/widget/poll/PollNavigateItemDetail.js

View file
  • Ignore whitespace
           postCreate : function() {
               //dojo.connect(this._publish, "onClick", dojo.hitch(this, this._validatePoll));
               this._remove.onClick = dojo.hitch(this, function() {
-                  console.info("json service to remove");
+                  _ENME.log("json service to remove");
               });
           },
 
               this.addRow("Display aditional information", data.poll_bean.is_show_additional_info, dojo.hitch(this, this._updatePollParameters), "additional-info");
               this.addRow("Make result public", data.poll_bean.show_resultsPoll, dojo.hitch(this, this._updatePollParameters), "change-display-results");
               this.addRow("Make result public", data.poll_bean.show_resultsPoll, dojo.hitch(this, this._updatePollParameters), "change-display-results");
-              var nodeId = this.id+"_chart";
+              var nodeId = this.id + "_chart";
               dojo.empty(dojo.byId(nodeId));
               //if results are empty it's needed display a "no results" option
               if (data.poll_results.length > 0) {
-            this.widgetChart = this.buildChart({
-             id : nodeId,
-             results : this._convertToChartAnswer(
-                   this._mergeResultsAnswers(
-                       data.poll_list_answers,
-                       data.poll_results))
-             });
-                this.renderChart(this.widgetChart);
+                 this.widgetChart = this.buildChart({
+                 id : nodeId,
+                 results : this._convertToChartAnswer(
+                       this._mergeResultsAnswers(
+                           data.poll_list_answers,
+                           data.poll_results))
+                 });
+                 this.renderChart(this.widgetChart);
               } else {
                 var node = dojo.byId(nodeId),
                 no_results = dojo.create('div');
           _convertToChartAnswer : function(answers) {
               var array = [];
               dojo.forEach(answers, function(answer) {
-                 array.push([answer.answers, answer.votes == undefined ? 0 : answer.votes , answer.color]);
+                 array.push([answer.answers.substring(0, 8), answer.votes == undefined ? 0 : answer.votes , answer.color]);
               });
               return array;
           }

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

View file
  • Ignore whitespace
-<div class="web-poll-wrapper web-pattern enme-text">
+<div class="web-poll-wrapper web-pattern enme-text enme-dnd">
     <div class="web-poll-question">
-         <div class="web-poll-section spaceBlock">
-            <div class="web-poll-section-title default-background-dark-color">
+         <div class="web-poll-section web-tweetpoll-section">
+            <div class="web-poll-section-title ">
                 ${i18nMessage.poll_create_question_title}
              </div>
              <div class="space">
             </div>
         </div>
 
-         <div class="web-poll-section spaceBlock">
-            <div class="web-poll-section-title default-background-dark-color">
+         <div class="web-poll-section web-tweetpoll-section">
+            <div class="web-poll-section-title ">
                    ${i18nMessage.poll_create_build_answers}
              </div>
              <div class="space">
                          label="${i18nMessage.poll_create_allow_new_responses}"></div>
               </div>
          </div>
-         <div class="web-poll-section spaceBlock">
-            <div class="web-poll-section-title default-background-dark-color">
+         <div class="web-poll-section web-tweetpoll-section">
+            <div class="web-poll-section-title ">
                 ${i18nMessage.poll_create_poll_options}
              </div>
              <div class="space">
                            <h2 class="default-dark-color">
                                 ${i18nMessage.poll_create_limits}
                            </h2>
-                           <div id="repeated"  data-dojo-type="me/web/widget/options/RepeatedVotes" class="space"></div>
-                           <div id="limit" data-dojo-type="me/web/widget/options/LimitVotes" class="space"></div>
-                           <div id="close" data-dojo-type="me/web/widget/options/DateToClose" class="space"></div>
+                           <div id="repeated"  data-dojo-type="me/web/widget/options/RepeatedVotes" class=""></div>
+                           <div id="limit" data-dojo-type="me/web/widget/options/LimitVotes" class=""></div>
+                           <div id="close" data-dojo-type="me/web/widget/options/DateToClose" class=""></div>
                       </div>
                       <div class="section-default">
                            <h2 class="default-dark-color">

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

View file
  • Ignore whitespace
                             ${i18nMessage.detail_manage_favorites}
                         </span>
                     </div>
-                    <div class="optionItem"
-                        data-dojo-attach-event="onclick:_searchByScheduled" type="SCHEDULED">
-                        <span>
-                            ${i18nMessage.detail_manage_scheduled}
-                        </span>
-                    </div>
                     <div class="optionItem" data-dojo-attach-event="onclick:_searchByAll"
                         type="ALL">
                         <span>
         <article style="margin-left: 202px;">
             <div class="web-list-tweet">
                 <!-- Drop Down Menu -->
-                <div style="padding: 10px; color: rgb(255, 255, 255);
+                <div class="enme-ui-gradient-header-color default-top-menu" style="padding: 10px; color: rgb(255, 255, 255);
                      font-size: 16px;
                      background-color: #595959;
                      overflow: auto;">

File enme-war/src/main/webapp/resource/js/me/web/widget/support/DnD.js

View file
  • Ignore whitespace
-/**
- * Dnd Support.
- * @author Picado, Juan juanATencuestame.org
- * @since 21/08/2011
- */
 define([
      "dojo/_base/declare",
-     "dojo/dnd/Source",
-     "dojo/dnd/Manager",
-     "dojo/_base/lang",
-     "me/web/widget/pictures/Avatar",
      "me/core/enme"],
     function(
     declare,
-    Source,
-    Manager,
-    lang,
-    Avatar,
     _ENME) {
 
-   lang.extend(Manager.manager, {
-
-// 	   TODO: To customize the avatar
-//     makeAvatar: function() {
-//         return new Avatar(this);
-//     },
-
-     updateAvatar: function() {
-          this.avatar.update();
-     },
-     // avatar's offset from the mouse
-     OFFSET_X: 0,
-     OFFSET_Y: 0,
-     canDrop: function(flag){
-         //console.debug("canDrop flag", flag);
-         // summary:
-         //		called to notify if the current target can accept items
-         var canDropFlag = Boolean(this.target && flag);
-         //console.debug("canDrop canDropFlag", canDropFlag);
-         if(this.canDropFlag != canDropFlag){
-             this.canDropFlag = canDropFlag;
-             this.avatar.update();
-         }
-     },
-     overSource: function(source){
-         //console.debug("overSource source", source.node);
-         // summary:
-         //		called when a source detected a mouse-over condition
-         // source: Object
-         //		the reporter
-         if (this.avatar) {
-             this.target = (source && source.targetState != "Disabled") ? source : null;
-             this.canDropFlag = Boolean(this.target);
-             this.avatar.update();
-         }
-         dojo.publish("/dnd/source/over", [source]);
-     }
-});
-
   return declare(null, {
 
-    /*
-    *
-    */
-   node : null,
-
-   /*
-    *
-    */
-   sourceDndWidget : null,
-
-   /*
-    *
-    */
-   accept : [],
+    isDnD : false,
 
-   /*
-    *
-    */
-   copyOnly : false,
-
-   /*
-    *
-    */
-   selfCopy : false,
-
-   /*
-    *
-    */
-   selfAccept : true,
-
-   /*
-    *
-    */
-   withHandles : true,
-
-   /*
-    *
-    */
-   autoSync : true,
-
-   /*
-    *
-    */
-   isSource : true,
-
-   /*
-    *
-    */
-   constructor: function() {
-       this.node = null;
-   },
-
-   /*
-    *
-    */
-   enableDndSupport : function(node, customCreator) {
-       this.node = node;
-       var params = {
-                   accept: this.accept,
-                   copyOnly: this.copyOnly,
-                   selfCopy : this.selfCopy,
-                   selfAccept: this.selfAccept,
-                   withHandles : this.withHandles,
-                   autoSync : this.autoSync,
-                   isSource : this.isSource
-                   //creator: this.dndNodeCreator
-                   };
-       if (customCreator) {
-           //dojo.mixin(params, { creator: this.dndNodeCreator});
-       }
-       console.debug("dnd params", params);
-       var source  = new Source(this.node, params);
-           this.sourceDndWidget = source;
-           console.debug("enabled DND Source on ", this.node);
-       dojo.connect(source, "onDndDrop", dojo.hitch(this, this.onDndColumn));
-   },
-
-   /*
-    * on drop on folder.
-    */
-   onDndColumn : function(source, nodes, copy, target) {
-           dojo.forEach(dojo.query(".dojoDndItemSelected"), function(item){
-               dojo.removeClass(item, "dojoDndItemSelected");
-           });
-           dojo.forEach(dojo.query(".dojoDndItemAnchor"), function(item){
-               dojo.removeClass(item, "dojoDndItemAnchor");
-           });
-           if(dojo.dnd.manager().target !== this.sourceDndWidget){
-               return;
-           }
-           if(dojo.dnd.manager().target == dojo.dnd.manager().source){
-               this._dndAction();
-           }
-   },
-
-   /*
-    *
-    */
-   addItems : function(array){
-        this.sourceDndWidget.insertNodes(false, itemArray);
-   },
-
-   /*
-    *
-    */
-   addItem : function(node) {
-       var itemArray = [];
-       itemArray.push(node);
-          this.sourceDndWidget.insertNodes(false, itemArray);
-  },
-
-   /*
-    *
-    */
-   _dndAction : function(){
-        dojo.forEach(this.sourceDndWidget.getSelectedNodes(), dojo.hitch(this, function(item) {
-            console.debug("DND item", item);
-      }));
-   },
-
-   /*
-    * dnd node creator.
-    */
-   dndNodeCreator : function (item, hint) {
-       //console.debug("hint", hint);
-       //console.debug("item", item);
-       var tr = document.createElement("div");
-       tr.innerHTML = "Item Dropped...";
-       return {node: tr, data: item, type: "poll"};
-   }
+    DnDManager : null,
 
    /**
-    * TODO: in this place should be move all DnD code repeated in another widgets.
-    * TweetpollList.
-    * DashboardLayout.
-    * FolderActions.
+    *
     */
+    constructor : function() {
+        this.isDnD = Modernizr.draganddrop;
+    },
+
+    /**
+     * Enable dnd support on a list of nodes.
+     * @param nodes
+     * @param handlers
+     * @method
+     */
+    enableDnDSupport : function (nodes , handlers) {
+      [].forEach.call(nodes, function(col) {
+          col.addEventListener('dragstart', handlers.dragstart || function(){}, false);
+          col.addEventListener('dragenter', handlers.dragenter || function(){}, false);
+          col.addEventListener('dragover', handlers.dragover || function(){}, false);
+          col.addEventListener('dragleave', handlers.dragleave || function(){}, false);
+          col.addEventListener('drop', handlers.drop || function(){}, false);
+          col.addEventListener('dragend', handlers.dragend || function(){}, false);
+          col.addEventListener('drag', handlers.drag || function(){}, false);
+      });
+    },
+
+    // function handleDragStart(e) {
+    //    this.style.opacity = '0.4';  // this / e.target is the source node.
+    // }
 
   });
-});
+});
+// /**
+//  * Dnd Support.
+//  * @author Picado, Juan juanATencuestame.org
+//  * @since 21/08/2011
+//  */
+// define([
+//      "dojo/_base/declare",
+//      "dojo/dnd/Source",
+//      "dojo/dnd/Manager",
+//      "dojo/_base/lang",
+//      "me/web/widget/pictures/Avatar",
+//      "me/core/enme"],
+//     function(
+//     declare,
+//     Source,
+//     Manager,
+//     lang,
+//     Avatar,
+//     _ENME) {
+
+//    lang.extend(Manager.manager, {
+
+// // 	   TODO: To customize the avatar
+// //     makeAvatar: function() {
+// //         return new Avatar(this);
+// //     },
+
+//      updateAvatar: function() {
+//           this.avatar.update();
+//      },
+//      // avatar's offset from the mouse
+//      OFFSET_X: 0,
+//      OFFSET_Y: 0,
+//      canDrop: function(flag){
+//          //console.debug("canDrop flag", flag);
+//          // summary:
+//          //		called to notify if the current target can accept items
+//          var canDropFlag = Boolean(this.target && flag);
+//          //console.debug("canDrop canDropFlag", canDropFlag);
+//          if(this.canDropFlag != canDropFlag){
+//              this.canDropFlag = canDropFlag;
+//              this.avatar.update();
+//          }
+//      },
+//      overSource: function(source){
+//          //console.debug("overSource source", source.node);
+//          // summary:
+//          //		called when a source detected a mouse-over condition
+//          // source: Object
+//          //		the reporter
+//          if (this.avatar) {
+//              this.target = (source && source.targetState != "Disabled") ? source : null;
+//              this.canDropFlag = Boolean(this.target);
+//              this.avatar.update();
+//          }
+//          dojo.publish("/dnd/source/over", [source]);
+//      }
+// });
+
+//   return declare(null, {
+
+//     /*
+//     *
+//     */
+//    node : null,
+
+//    /*
+//     *
+//     */
+//    sourceDndWidget : null,
+
+//    /*
+//     *
+//     */
+//    accept : [],
+
+//    /*
+//     *
+//     */
+//    copyOnly : false,
+
+//    /*
+//     *
+//     */
+//    selfCopy : false,
+
+//    /*
+//     *
+//     */
+//    selfAccept : true,
+
+//    /*
+//     *
+//     */
+//    withHandles : true,
+
+//    /*
+//     *
+//     */
+//    autoSync : true,
+
+//    /*
+//     *
+//     */
+//    isSource : true,
+
+//    /*
+//     *
+//     */
+//    constructor: function() {
+//        this.node = null;
+//    },
+
+//    /*
+//     *
+//     */
+//    enableDndSupport : function(node, customCreator) {
+//        this.node = node;
+//        var params = {
+//                    accept: this.accept,
+//                    copyOnly: this.copyOnly,
+//                    selfCopy : this.selfCopy,
+//                    selfAccept: this.selfAccept,
+//                    withHandles : this.withHandles,
+//                    autoSync : this.autoSync,
+//                    isSource : this.isSource
+//                    //creator: this.dndNodeCreator
+//                    };
+//        if (customCreator) {
+//            //dojo.mixin(params, { creator: this.dndNodeCreator});
+//        }
+//        console.debug("dnd params", params);
+//        var source  = new Source(this.node, params);
+//            this.sourceDndWidget = source;
+//            console.debug("enabled DND Source on ", this.node);
+//        dojo.connect(source, "onDndDrop", dojo.hitch(this, this.onDndColumn));
+//    },
+
+//    /*
+//     * on drop on folder.
+//     */
+//    onDndColumn : function(source, nodes, copy, target) {
+//            dojo.forEach(dojo.query(".dojoDndItemSelected"), function(item){
+//                dojo.removeClass(item, "dojoDndItemSelected");
+//            });
+//            dojo.forEach(dojo.query(".dojoDndItemAnchor"), function(item){
+//                dojo.removeClass(item, "dojoDndItemAnchor");
+//            });
+//            if(dojo.dnd.manager().target !== this.sourceDndWidget){
+//                return;
+//            }
+//            if(dojo.dnd.manager().target == dojo.dnd.manager().source){
+//                this._dndAction();
+//            }
+//    },
+
+//    /*
+//     *
+//     */
+//    addItems : function(array){
+//         this.sourceDndWidget.insertNodes(false, itemArray);
+//    },
+
+//    /*
+//     *
+//     */
+//    addItem : function(node) {
+//        var itemArray = [];
+//        itemArray.push(node);
+//           this.sourceDndWidget.insertNodes(false, itemArray);
+//   },
+
+//    /*
+//     *
+//     */
+//    _dndAction : function(){
+//         dojo.forEach(this.sourceDndWidget.getSelectedNodes(), dojo.hitch(this, function(item) {
+//             console.debug("DND item", item);
+//       }));
+//    },
+
+//    /*
+//     * dnd node creator.
+//     */
+//    dndNodeCreator : function (item, hint) {
+//        //console.debug("hint", hint);
+//        //console.debug("item", item);
+//        var tr = document.createElement("div");
+//        tr.innerHTML = "Item Dropped...";
+//        return {node: tr, data: item, type: "poll"};
+//    }
+
+//    /**
+//     * TODO: in this place should be move all DnD code repeated in another widgets.
+//     * TweetpollList.
+//     * DashboardLayout.
+//     * FolderActions.
+//     */
+
+//   });
+// });

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

View file
  • Ignore whitespace
                      "shortUrl" : encuestame.shortUrlProvider[1].code
                 };
                 //console.debug("params", params);
+                var parent = this;
                 var load = dojo.hitch(this, function(data) {
                     //console.debug(data);
-                    this.loading_hide();
+                    parent.loading_hide();
                     var items = [];
                     var answerWidget = new AnswerItem({
                         answer :{

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

View file
  • Ignore whitespace
                   parent._loading.hide();
                   parent.errorMessage(error);
               };
+
               //
               this._loading.show(this.i18nMessage.loading_message, _ENME.MESSAGES_TYPE.WARNING);
               this.getURLService().get(this.url, params, load, error , dojo.hitch(this, function() {

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

View file
  • Ignore whitespace
-<section class="answerItem dojoDndItem">
+<section class="answerItem">
     <div class="title"  data-dojo-attach-point="_item"></div>
     <div data-dojo-attach-point="_options" class="answerItem-options"></div>
 </section>