Ok i saw many post's on how to serialize the value of dragged items to get hash and they tell how to save them. Now the question is how do i persist the dragged items the next time when user log's in using the has value that i got
eg:
<ul class="list">
<li id="id_1">
<div class="item ui-corner-all ui-widget ui-widget-content">
</div>
</li>
<li id="id_2">
<div class="item ui-corner-all ui-widget ui-widget-content">
</div>
</li>
<li id="id_3">
<div class="item ui-corner-all ui-widget ui-widget-content">
</div>
</li>
<li id="id_4">
<div class="item ui-corner-all ui-widget">
</div>
</li>
</ul>
which on serialize will give
"id[]=1&id[]=2&id[]=3&id[]=4"
Now think that i saved it to Sql server database in a single field called SortOrder.
Now how do i get the items to these order again ?
the code to make these sort is below,without which people didn't know which library i had used to sort and serialize
<script type="text/javascript">
$(document).ready(function() {
$(".list li").css("cursor", "move");
$(".list").sortable();
});
</script>
I believe what Brian is saying is that your table should look like this, if they were sorted in ascending order by the user:
ID Sort Order
1 1
2 2
3 3
4 4
If they were sorted in descending order by the user, the table would look like this:
ID Sort Order
1 4
2 3
3 2
4 1
Then, when you query the database, you would do
SELECT [ID], [Sort Order]
FROM [thetable]
ORDER BY [Sort Order]
and the list would be sorted by the server.
You can then just output the data in the order the server code provides it in.
Rather than storing a single field, can you store a SortOrder column with the data? You can update the DB with the new sort order, and when you query data from the DB, order it by the sort order. Otherwise, in code, you must do a programmatic sort ordering of data, querying the data into something, then looping through and copying the data to another array/list that's sorted based on this one field.
HTH.
Related
I'm trying to show the full name for each news item in a list. For the moment I have only the user id (nickname).
Is there a simple way (in existing .pt file) to show the full name of creator or owner instead of a nickname?
The page must work for anonymous users, too. I mean - the page must be public.
Some details:
<div class="container-fluid news-list-container"
tal:define="news_items python:context.getFolderContents(contentFilter={'portal_type':['News Item'], 'sort_on': 'Date', 'sort_order': 'descending',});
Batch python:modules['Products.CMFPlone'].Batch;
b_size python:4;
b_start python:0;
b_start request/b_start | b_start;
batch python:Batch(news_items, b_size, int(b_start), orphan=0);"
tal:condition="news_items">
<div class="news-list-items">
<tal:items tal:repeat="news_item batch">
<!-- News item -->
<div class="row news-item"
tal:define="news_object python:news_item.getObject();
news_date python:news_object.getField('modification_date').getAccessor(news_object)();
news_title python:news_object.getField('title').getAccessor(news_object)();
news_description python:news_object.getField('description').getAccessor(news_object)();
news_image python:news_object.getField('image').getAccessor(news_object)();
news_url python:news_object.absolute_url();
news_creators python:news_object.getField('creators').getAccessor(news_object)(); .... ...
<tal:fullname define="membership context/portal_membership;
info python:membership.getMemberInfo(user.getId());
fullname info/fullname">
You are are <span class="name" tal:content="fullname" />
</tal:fullname>
This example is taken from the plone documentation
You can get inspired a lot by this code:
https://github.com/collective/Products.Scrawl/blob/1021047c4ef6c2655d104e8b345a24140da9e4aa/Products/Scrawl/browser/blogentry_view.pt#L32
<tal:name tal:condition="item_creator"
tal:define="author python:context.portal_membership.getMemberInfo(item_creator)">
<span i18n:translate="label_by_author">Posted by
<a href="#"
title="Read more posts by this author"
tal:attributes="href string:${context/portal_url}/author/${item_creator}"
tal:content="python:author and author['fullname'] or item_creator"
tal:omit-tag="not:author"
i18n:domain="scrawl"
i18n:name="author"
i18n:attributes="title author_title">
Bob Dobalina
</a>
</span>
</tal:name>
Mind the possible performance issues.
A cached view method may work a lot better, e.g.:
#memoize
def userid2fullname(self, userid):
pm = api.portal.get_tool('portal_membership')
memberinfo = pm.getMemberInfo(userid)
return memberinfo and memberinfo['fullname'] or userid
I made a block to loop though the database and grab all the numbers and display them on an unordered list but they are all coming back on the same line like they are all one item. I feel that the block should automatically separate them?
`<h1>Listing Numbers</h1>
<div class='from-group'>
<ul>
<li class="numbers">
<% #people.each do |person| %>
<%= person.phone_number %>
<% end %>
</li>
</ul>
</div>
`
What I think is happening is that all the numbers are on ONE li rather than individual li...
See the difference:
<h1>Listing Numbers</h1>
<div class='from-group'>
<ul>
<li class="numbers">
Item 1 Item 2 Item 3 (we're all in the same li)
</li>
</ul>
</div>
<h1>Listing Numbers</h1>
<div class='from-group'>
<ul>
<li class="numbers">Item 1 Separate li</li>
<li class="numbers">Item 2 Separate li</li>
<li class="numbers">Item 3 Separate li</li>
</ul>
</div>
Looks like there's one iteration only and person.phone_number prints all three numbers at once. Check the person. I think it holds all three numbers in one attribute phone_number. In this case you could split the numbers and join them together with a html line break.
<%= person.phone_number.split(" ").join("<br />") %>
But with this solution you keep the numbers in one li element only.
The other way would be to think about a database migration to store the numbers within different attributes (phone, mobil, fax, ...).
I have a template (tmpl1) which refers to a collection projectdetails, in the following code I can successfully show {{detailname}} what is based on the collectiondata projectdetails.detailname
But now I need to show also the Projectname which is in projects.name I do have the project._id saved in projectdetails.projectId
How can I now define a handelbar like {{projectName}} to display the project name.
I have tried to define this in projectdetails.js as helper but I was not successful. Can someone please add a code sniplet which explains how to define the handelbar and how to retrieve the data?
<template name="tmpl1">
<div id="example" class="panel">
<ol class="breadcrumb">
<li><i class="fa fa-home"></i> Start</li>
<li><i class="fa fa-cubes"></i> Projekte</li>
<li><i class="fa fa-cogs"></i> Details</li>
<li class="active">{{detailname}} {{projectName}}</li>
</ol>
</div>
You can just add a helper for projectName which joins the two collections.
The context of your template appears to be a "project detail" document, so inside of the projectName helper, this.projectId should be the id of the project document. Assuming the collection is called Projects and each project has a name field, the code should look something like this:
Template.tmpl1.helpers({
projectName: function() {
var project = Projects.findOne(this.projectId);
return project && project.name;
}
});
So, suppose I have this viewmodel named people which consists of an array of person object literals, like
[{ name = John, age = 30, sex = male },
{ name = Mike, age = 29, sex = male },
{ name = Anna, age = 28, sex = female }]
And suppose I wanted to data-bind each person to an <li>, like
<ul data-bind="foreach: people">
<li data-bind="text: name"></li>
</ul>
But, is it possible, maybe through data-bind="with: $data", to bind the whole person object to the <li> so, for example, when I click the <li> some other <div> displays the rest of the information, which in this example would be age and sex?
It's like I wanted the <li> to hold the person object data, so I could use it somewhere else.
Generally, you would want to create like a selectedPerson observable at the view model level and then you could do something like:
<ul data-bind="foreach: people">
<li data-bind="click: $parent.selectedPerson">
<span data-bind="text: name"></span>
<div data-bind="visible: $parent.selectedPerson() === $data">
<span data-bind="text: age"></span>
</div>
</li>
</ul>
You could certainly use a link/button around the name, if you like. When you click on it, selectedPerson will be used as the handler and passed the current data as its first argument. Since, selectedPerson is actually an observable, it will populate it with the data as its value.
Otherwise, you could certainly have another area to display the details where you do:
<div data-bind="with: selectedPerson">
....
</div>
Quick fiddle: http://jsfiddle.net/rniemeyer/8dRZ4/
Ok I saw many posts on how to serialize the value of dragged items to get hash and they tell how to save them. Now the question is how do I persist the dragged items the next time when user log's in using the has value that I got
eg:
<ul class="list">
<li id="id_1">
<div class="item ui-corner-all ui-widget ui-widget-content">
</div>
</li>
<li id="id_2">
<div class="item ui-corner-all ui-widget ui-widget-content">
</div>
</li>
<li id="id_3">
<div class="item ui-corner-all ui-widget ui-widget-content">
</div>
</li>
<li id="id_4">
<div class="item ui-corner-all ui-widget">
</div>
</li>
</ul>
which on serialize will give
"id[]=1&id[]=2&id[]=3&id[]=4"
Now think that I saved it to Sql server database in a single field called SortOrder.
Now how do I get the items to these order again ?
the code to make these sort is below, without which people didn't know which library I had used to sort and serialize
<script type="text/javascript">
$(document).ready(function() {
$(".list li").css("cursor", "move");
$(".list").sortable();
});
</script>
There are a few options. One option is to do the sorting server-side. You would read out that string in .NET to generate the list, in order, on the fly. Then output it to the browser.
Another option would be output the serialized string as a string variable in javascript. You could then use jQuery to reorder the elements. The problem with this method is that there would probably be a flash where the unordered list would display and then the correctly ordered list would appear.