diff --git a/samples/gadgets-sample/exo-gadget-resources/src/main/webapp/skin/exo-gadget/gadget-common.css b/samples/gadgets-sample/exo-gadget-resources/src/main/webapp/skin/exo-gadget/gadget-common.css index 58811aa5c4..aa420ef001 100644 --- a/samples/gadgets-sample/exo-gadget-resources/src/main/webapp/skin/exo-gadget/gadget-common.css +++ b/samples/gadgets-sample/exo-gadget-resources/src/main/webapp/skin/exo-gadget/gadget-common.css @@ -66,7 +66,7 @@ img { } .light_message { - color: #333; + color: #999999; } .UIGadgetThemes .IconDropDown { diff --git a/samples/gadgets-sample/gadgets/src/main/webapp/gadgets/FeaturedPoll/Poll.xml b/samples/gadgets-sample/gadgets/src/main/webapp/gadgets/FeaturedPoll/Poll.xml index 3612cf1089..09b2878c9c 100644 --- a/samples/gadgets-sample/gadgets/src/main/webapp/gadgets/FeaturedPoll/Poll.xml +++ b/samples/gadgets-sample/gadgets/src/main/webapp/gadgets/FeaturedPoll/Poll.xml @@ -1,16 +1,14 @@ - - - - - - - - + + + + + + + + + @@ -26,33 +24,33 @@ - - + + + - - - - - - - - - -
-
- __MSG_title__ - -
- -
-
-
-
-
-
- ]]> -
-
+ + + + + + + + + +
+
+ __MSG_title__ + +
+ +
+
+
+
+
+
+ ]]> + + \ No newline at end of file diff --git a/samples/gadgets-sample/gadgets/src/main/webapp/gadgets/FeaturedPoll/script/poll.js b/samples/gadgets-sample/gadgets/src/main/webapp/gadgets/FeaturedPoll/script/poll.js index 6963b8c8e3..673430ac0b 100644 --- a/samples/gadgets-sample/gadgets/src/main/webapp/gadgets/FeaturedPoll/script/poll.js +++ b/samples/gadgets-sample/gadgets/src/main/webapp/gadgets/FeaturedPoll/script/poll.js @@ -1,208 +1,245 @@ function init() { - - createPollDiv(); - // Adding eXo Platform container information - var opts = {}; - opts[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [ - "portalName", - "restContext", - "host"]; - var req = opensocial.newDataRequest(); - req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER, opts), 'viewer'); - req.send(createURL); - $('.settingBt').click(function(){ - config(); - }); + createPollDiv(); + // Adding eXo Platform container information + var opts = {}; + opts[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = ["portalName", "restContext", "host" ]; + var req = opensocial.newDataRequest(); + req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER, opts), 'viewer'); + req.send(createURL); + $('.settingBt').click(function() { + config(); + }); } function createPollDiv() { - var prefs = new gadgets.Prefs(); - var forumURL = window.location.protocol + "//" + window.location.host + parent.parent.eXo.env.portal.context + "/"+ parent.parent.eXo.env.portal.portalName +"/forum"; - adjustHeight(); + var prefs = new gadgets.Prefs(); + var forumURL = window.location.protocol + "//" + window.location.host + parent.parent.eXo.env.portal.context + "/" + parent.parent.eXo.env.portal.portalName + "/forum"; + adjustHeight(); } function createURL(data) { - this.viewer = data.get('viewer').getData(); - var hostName = viewer.getField('hostName'); - var portalName = viewer.getField('portalName'); - var restContext = viewer.getField('restContextName'); - baseURL = hostName + "/" + restContext + "/ks/poll/"; - var url = baseURL + "viewpoll/pollid"; - $.getJSON(url,createPollList); + this.viewer = data.get('viewer').getData(); + var hostName = viewer.getField('hostName'); + var portalName = viewer.getField('portalName'); + var restContext = viewer.getField('restContextName'); + baseURL = hostName + "/" + restContext + "/ks/poll/"; + var url = baseURL + "viewpoll/pollid"; + $.getJSON(url, createPollList); } -function createPollList(data){ - var prefs = new gadgets.Prefs(); - - var pollIds = data.pollId; - var pollNames = data.pollName; - var len = pollIds.length; - - if (data.isAdmin == "true") { - var html = []; - html.push('
'); - html.push('
'); - html.push(''); - html.push('
'); - html.push(''); - html.push(''); - html.push(''); - html.push('
'); - html.push('
'); - html.push('
'); - $('#listpoll').html(html.join('')); - } - - var randomPollId = 0; - var url = baseURL + "viewpoll/" + pollIds[randomPollId]; +function createPollList(data) { + var prefs = new gadgets.Prefs(); + var pollIds = data.pollId; + var pollNames = data.pollName; + var len = pollIds.length; + var votedValue = prefs.getString('votedValue'); + + if (data.isAdmin == "true") { + var html = []; + html.push('
'); + html.push('
'); + html.push(''); + html.push('
'); + html.push(''); + html.push(''); + html.push(''); + html.push('
'); + html.push('
'); + html.push('
'); + $('#listpoll').html(html.join('')); + } - if(len == 0){ - document.getElementById("poll").innerHTML = "
" + prefs.getMsg("nopoll") + "
"; - adjustHeight(); - return; + var randomPollId = 0; + var url = baseURL + "viewpoll/" + pollIds[randomPollId]; + if (len == 0) { + document.getElementById("poll").innerHTML = "
" + prefs.getMsg("nopoll") + "
"; + adjustHeight(); + return; + } + + // initialize values for vote options + if (votedValue) { + var selVote = document.getElementById("selVoteQuestions"); + selVote.value = votedValue; + selVote.onchange(); + } else { + $.getJSON(url, function(data) { + showPoll(data, false); + }); + } +} - } - - $.getJSON(url,function(data){ - showPoll(data, false); - }); +function showPoll(data, isVoteAgain) { + var options = data.option; + var prefs = new gadgets.Prefs(); + var lblVote = prefs.getMsg("vote"); + var question = data.question; + var pollId = data.id; + var parentPath = data.parentPath; + var haveTopic = parentPath.indexOf("ForumData/CategoryHome"); // check topic of poll if toptic is exist + if (!data.showVote || isVoteAgain) { + html = []; + if (haveTopic) { + var prefs = new gadgets.Prefs(); + var topicId = pollId.replace("poll", "topic"); + var topicURL = window.location.protocol + "//" + window.location.host + parent.parent.eXo.env.portal.context + "/" + parent.parent.eXo.env.portal.portalName + "/forum/topic/" + topicId; + html.push('
' + question + '' + prefs.getMsg("discuss") + '
'); + } else { + html.push('
' + question + '
'); + } + html.push('
'); + html.push('') + if (data.isMultiCheck) { + for ( var i = 0, len = options.length; i < len; i++) { + html.push(''); + } + } else { + for ( var i = 0, len = options.length; i < len; i++) { + html.push(''); + } + } + html.push("
"); + html.push(""); + + $('#poll').html(html.join('')); + } else { + showResult(data); + } + adjustHeight(); + $("[data-toggle=tooltip]").tooltip(); } +function showResult(data) { + var prefs = new gadgets.Prefs(); + var voters = data.infoVote[data.infoVote.length - 1]; + var options = data.option; + var vote = data.vote; + var question = data.question; + var msgOption = prefs.getMsg('option'); + var msgPercent = prefs.getMsg('percent'); + var msgVoter = prefs.getMsg('voter'); + var msgTotal = prefs.getMsg('total'); + var pollId = data.id; + var parentPath = data.parentPath; + var haveTopic = parentPath.indexOf("ForumData/CategoryHome"); // check topic of poll if toptic is exist + var tbl = []; -function showPoll(data, isVoteAgain){ - var options = data.option; - var prefs = new gadgets.Prefs(); - var lblVote = prefs.getMsg("vote"); - var question = data.question; - var pollId = data.id; - var parentPath = data.parentPath; - var haveTopic = parentPath.indexOf("ForumData/CategoryHome"); //check topic of poll if toptic is exist - if(!data.showVote || isVoteAgain){ - html = []; - if(haveTopic){ - var prefs = new gadgets.Prefs(); - var topicId= pollId.replace("poll","topic"); - var topicURL = window.location.protocol + "//" + window.location.host + parent.parent.eXo.env.portal.context + "/"+ parent.parent.eXo.env.portal.portalName +"/forum/topic/" + topicId; - html.push('
' + question + '' + prefs.getMsg("discuss") + '
'); - } - else{ - html. push('
' + question + '
'); - } - html.push('
'); - html.push('') - if(data.isMultiCheck){ - for(var i = 0, len = options.length; i < len; i++){ - html.push(''); - } - } else { - for(var i = 0, len = options.length; i < len; i++){ - html.push(''); - } - } - html.push("
"); - html.push(""); - - $('#poll').html(html.join('')); - }else{ - showResult(data); + if (haveTopic) { + var prefs = new gadgets.Prefs(); + var topicId = pollId.replace("poll", "topic"); + var topicURL = window.location.protocol + "//" + window.location.host + parent.parent.eXo.env.portal.context + "/" + parent.parent.eXo.env.portal.portalName + "/forum/topic/" + topicId; + tbl.push('
' + question + '' + prefs.getMsg('discuss') + '
'); + } else { + tbl.push('
' + question + '
'); + } + + tbl.push(''); + tbl.push(''); + for ( var i = 0, len = options.length; i < len; i++) { + var result = Math.round(vote[i]); + var style = ""; + if (result > 5) { + var style = 'width:' + result + '%;'; + } else { + var style = 'width:' + result + '%;'; + } + + tbl.push(''); + } + tbl.push(''); + tbl.push('
' + options[i] + '
 
' + result + '%
'); + tbl.push('
'); + if (data.isAgainVote) { + tbl.push(""); + $("#btnVoteAgain").live("click", function() { + showPoll(data, true); + }); + } + tbl.push(' ' + msgTotal + ': ' + voters + ' ' + msgVoter + ''); + tbl.push('
'); + + $("#poll").html(tbl.join('')); + // Adjust width of progress bar if it's too short + var featPoll = document.getElementById('uiFeaturePoll'); + var labelVote = featPoll.getElementsByClassName('label-vote'); + var isWindowMode = featPoll.offsetWidth < 400 ? false : true; + if (!isWindowMode) { + $(featPoll).addClass('minimize'); + var children = featPoll.getElementsByTagName('td'); + if (children) + children[0].style.width = 105; + } + else { + $(featPoll).addClass('maximize'); } - adjustHeight(); + + makeTooltipForLabel(labelVote, isWindowMode); + adjustHeight(); } -function showResult(data){ - var prefs = new gadgets.Prefs(); - var voters = data.infoVote[data.infoVote.length-1]; - var options = data.option; - var vote = data.vote; - var question = data.question; - var msgOption = prefs.getMsg('option'); - var msgPercent = prefs.getMsg('percent'); - var msgVoter = prefs.getMsg('voter'); - var msgTotal = prefs.getMsg('total'); - var pollId = data.id; - var parentPath = data.parentPath; - var haveTopic = parentPath.indexOf("ForumData/CategoryHome"); //check topic of poll if toptic is exist - var tbl = []; - - if(haveTopic){ - var prefs = new gadgets.Prefs(); - var topicId= pollId.replace("poll","topic"); - var topicURL = window.location.protocol + "//" + window.location.host + parent.parent.eXo.env.portal.context + "/"+ parent.parent.eXo.env.portal.portalName + "/forum/topic/" + topicId; - tbl.push('
' + question + '' + prefs.getMsg('discuss') + '
'); - } - else{ - tbl.push('
' + question + '
'); - } - - tbl.push(''); - tbl.push(''); - for(var i = 0, len = options.length; i < len; i++){ - var result = Math.round(vote[i]); - var style =""; - if(result>5){ - var style = 'width:' + result + '%;'; - } - else{ - var style = 'width:' + result + '%;'; - } - - tbl.push(''); - } - tbl.push(''); - tbl.push('
' + options[i] + '
 
' + result + '%
'); - tbl.push('
'); - if(data.isAgainVote){ - tbl.push(""); - $("#btnVoteAgain").live("click", function(){ - showPoll(data, true); - }); - } - tbl.push(' '+ msgTotal +': ' + voters + ' ' + msgVoter +''); - tbl.push('
'); - - $("#poll").html(tbl.join('')); - adjustHeight(); +function makeTooltipForLabel(labels, mode) { + if (labels) { + for (var j = 0; j < labels.length; j++) { + var width = labels[j].offsetWidth; + console.log(width); + + if (mode == false) { + if (width > 105) + setAttribute(labels[j], 'data-toggle', 'tooltip'); + labels[j].style.width = 100; + } + } + } } -function doVote(el){ - var votes = []; - $(".radio:checked").each(function(){ - votes.push($(this).val()); - }); - - if(votes.length < 1) { - $("input:checked").each(function() { - votes.push($(this).val()); - }); - if(votes.length < 1) return; - } - - var pollId = el.form.elements["pollid"].value; - var url = baseURL + "votepoll/" + pollId + "/" + votes.join(":"); - $.getJSON(url,showResult); +function setAttribute(element, property, value) { + return element.setAttribute(property, value); +} + +function doVote(el) { + var votes = []; + $(".radio:checked").each(function() { + votes.push($(this).val()); + }); + + if (votes.length < 1) { + $("input:checked").each(function() { + votes.push($(this).val()); + }); + if (votes.length < 1) { + return; + } + } + + var pollId = el.form.elements["pollid"].value; + var url = baseURL + "votepoll/" + pollId + "/" + votes.join(":"); + $.getJSON(url, showResult); } -function changeVote(obj){ - var selectedValue = obj.options[obj.selectedIndex].value; - var url = baseURL + "viewpoll/" + selectedValue; - $.getJSON(url,function(data){ - showPoll(data, false); - }); - config(); +function changeVote(obj) { + var selectedValue = obj.options[obj.selectedIndex].value; + var url = baseURL + "viewpoll/" + selectedValue; + var prefs = new gadgets.Prefs(); + prefs.set('votedValue', selectedValue); + $.getJSON(url, function(data) { + showPoll(data, false); + }); + config(); } -function config(){ - if($('#listpoll').is(':visible')) - $('#listpoll').fadeOut("fast",adjustHeight); - else - $('#listpoll').fadeIn("fast",adjustHeight); - adjustHeight(); +function config() { + if ($('#listpoll').is(':visible')) { + $('#listpoll').fadeOut("fast", adjustHeight); + } else { + $('#listpoll').fadeIn("fast", adjustHeight); + } + adjustHeight(); } -function adjustHeight(){ - gadgets.window.adjustHeight($('.uiGadgetThemes').outerHeight()); +function adjustHeight() { + gadgets.window.adjustHeight($('.uiGadgetThemes').outerHeight()); } gadgets.util.registerOnLoadHandler(init); \ No newline at end of file diff --git a/samples/gadgets-sample/gadgets/src/main/webapp/skin/less/Poll.less b/samples/gadgets-sample/gadgets/src/main/webapp/skin/less/Poll.less index a406f5f01f..d86364da2a 100644 --- a/samples/gadgets-sample/gadgets/src/main/webapp/skin/less/Poll.less +++ b/samples/gadgets-sample/gadgets/src/main/webapp/skin/less/Poll.less @@ -1,10 +1,24 @@ .uiGadgetThemes{ .gadContent { padding: 8px 16px; + .question, .question .text{ + color: #2f5e92; + } .question{ - margin: 10px 0px 12px 0px; + margin: 5px 0 10px; text-decoration: none; - color: #2f5e92; + display: inline-block; + line-height: 18px; + > i { + float: left; + margin-right: 5px; + margin-top: 1px; + } + .text { + display: block; + line-height: 18px; + margin-left: 21px; + } } .poll{ h6{ @@ -38,14 +52,15 @@ width: 100%; margin: 10px 0; .label-vote{ - max-width: 170px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; + display: inline-block; } .percent{ - width: 40px; - padding-left: 12px; + width: 35px; + padding-left: 2px; + text-align: right; } } @@ -69,17 +84,34 @@ } .horizontalBG{ + width: 100%; height: 10px; border-radius: 5px; - background-image: linear-gradient(to bottom, #d3d3d3, #eaeaea); - box-shadow: 0 1px 1px #C0C0C0 inset; + background-color: #dcdcdc; + background-image: -moz-linear-gradient(top, #d3d3d3, #eaeaea); + background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#d3d3d3), to(#eaeaea)); + background-image: -webkit-linear-gradient(top, #d3d3d3, #eaeaea); + background-image: -o-linear-gradient(top, #d3d3d3, #eaeaea); + background-image: linear-gradient(to bottom, #d3d3d3, #eaeaea); + background-repeat: repeat-x; + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd3d3d3', endColorstr='#ffeaeaea', GradientType=0); + -webkit-box-shadow: 0 1px 1px #c0c0c0 inset; + -moz-box-shadow: 0 1px 1px #c0c0c0 inset; + box-shadow: 0 1px 1px #c0c0c0 inset; overflow: hidden; } .horizontalBar { height: 10px; border-radius: 5px 0 0 5px; - background-image: linear-gradient(to bottom, #5d83c3, #456697); + background-color: #5377b1; + background-image: -moz-linear-gradient(top, #5d83c3, #456697); + background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#5d83c3), to(#456697)); + background-image: -webkit-linear-gradient(top, #5d83c3, #456697); + background-image: -o-linear-gradient(top, #5d83c3, #456697); + background-image: linear-gradient(to bottom, #5d83c3, #456697); + background-repeat: repeat-x; + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5d83c3', endColorstr='#ff456697', GradientType=0); } .listpoll { @@ -98,6 +130,7 @@ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; + text-align: left; } } .selectbox{ @@ -136,4 +169,31 @@ margin: 0px; } } -} \ No newline at end of file + &.minimize { + .voteResult { + table-layout: fixed; + } + .gadContent { + .listpoll { + .control-group { + .control-label { + width: auto; + float: none; + padding: 0; + margin: 0 0 8px; + } + .controls { + margin-left: 0; + } + } + } + } + } + &.maximize { + .voteResult { + .label-vote { + padding-right: 10px; + } + } + } +}