-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#JC-1373 Add dynamic poll item functionality #40
base: master
Are you sure you want to change the base?
Changes from 1 commit
6131686
89e515a
2e93744
a502e68
aaeb704
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (C) 2011 JTalks.org Team | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
package org.jtalks.jcommune.web.view; | ||
|
||
import org.jtalks.jcommune.model.entity.Poll; | ||
|
||
/** | ||
* Contains configuration for Dynamic Poll Items | ||
* @author Andrey Ivanov | ||
*/ | ||
public class DynamicPollItemsConfig { | ||
|
||
public Integer getMaxPollItems(){ | ||
return Poll.MAX_ITEMS_NUMBER; | ||
} | ||
|
||
public Integer getMinPollItems(){ | ||
return Poll.MIN_ITEMS_NUMBER; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
$(document).ready(function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why 'poolNewTopic'? when editing we have a different behavior? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, while editing we can't change polls but finished date field. |
||
|
||
if ($("div.pollItemsValue").length == maxPollItems) { | ||
$("a#add").hide(); | ||
} | ||
|
||
$( "#sortable" ).sortable({update: function(event, ui) {reIndex()}}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $( "#sortable" ) spaces are't needed |
||
|
||
var name = $("#sortable").attr("rel"); | ||
|
||
$("a#add").click(function(e){ | ||
e.preventDefault(); | ||
length = $("div.pollItemsValue").length; | ||
if(length < maxPollItems) { | ||
newItem = $(".pollItemsValue:last").clone(); | ||
$(newItem).insertAfter(".pollItemsValue:last"); | ||
$("input[type=text]", newItem).val(""); | ||
reIndex(); | ||
if ($("div.pollItemsValue").length == maxPollItems) { | ||
$("a#add").hide(); | ||
} | ||
} | ||
}); | ||
|
||
$(".pollItemsValue .remove").live("click", function(e){ | ||
e.preventDefault(); | ||
if($("div.pollItemsValue").length > minPollItems) { | ||
$(this).closest('div.pollItemsValue').remove(); | ||
reIndex(); | ||
if ($("div.pollItemsValue").length < maxPollItems) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this check is unnecessary. if removed, then the length would be always less than maxPollItems |
||
$("a#add").show(); | ||
} | ||
} | ||
}); | ||
|
||
function reIndex(){ | ||
$(".pollItemsValue input[type=text]").each(function(index) { | ||
$(this).attr("name", name.replace("__index__", index)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check this place. after adding, the item is copied and it will have the name of last item (not contains index). or not? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When items is copied then all names are changed according to pattern and index. |
||
}); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would give the name just PollItemsConfignfig