If you look at my brief history of questions, I've seem to have built up a reputation for asking simple questions that I should have figured out the answers to myself, before wasting people's time. With this one though I'm genuinely stumped and I would greatly appreciate some help, so here goes...
I have a multi select list (will eventually use a jquery plugin to make it pretty) that will be populated based on some user criteria (in my example the options are hardcoded, but an example would be a 13 year old shouldn't be able to see rated "Mature" games in my game store).
Based on some search criteria (let's say we are searching by publisher, games available in a specific country, etc..) The counts for each multi-select item, should update as the search criteria changes and the counts change. (In my example I just change a value with a timer)
Here is the fiddle, http://jsfiddle.net/AMPBb/1/
It seems like there are a few ways I could solve this, like a countBinding on my SelectListItem with a displayText computed property, but I can't actually finish a working example. The first option that has the changing count is very hackerish, but demonstrates the functionality that I'm expecting. I haven't come across an example like this before, so I'm very interested in seeing what the best approach to solving this should be.
Thanks in advance for any help.
I would create a computed property label on your App.SelectListItem which is defined as follows, see http://jsfiddle.net/pangratz666/Y6467/
label: function() {
var text = this.get('text');
var value = this.get('value');
return '%# (%#)'.fmt(text, value);
}.property('text', 'value').cacheable()
Also note that you have to create a valueBinding to your 'App.CountModel.*' in your App.SelectListItem.
One more thing about naming convention: concrete instances should be named in lowerCase, so it's App.countModel. See http://www.emberist.com/2012/04/09/naming-conventions.html.
Related
I have a controller and a model that get some data from the server.
I'm trying to initialize two views, one for editing and one for showing a list of items related to this data. For example, the model holds some search properties which the user may edit. After editing the search params I want to switch between the two views and display the refined search results.
I can't find any sample that does such switching.
I tried using Ember.ContainerView samples but all seems to be failing with nasty runtime errors.
Not sure that I have any relevant code sample :-(
Any help would be gladly appreciated
I've put together a demo that toggles editing, nothing special but it simulates your use case I guess, have a look here.
Hope it helps.
Say I have a website that has 100 products. Then this is filtered down to 5 sections containing 20 products each. If you were in one of the sections that contained 20 products (e.g. toys), what would be the optimal method to display only 5 toys per page. At the bottom of the list would be next/previous buttons to show the next/previous set of 5 toys.
A better analogy would be google search. There are millions of results but only ~10 are shown at a given time.
So right now I'm using google app engine (python) and django templates. One way I thought of to remedy this problem would be making all the query results go into a div which could then be modified through javascript to give a similar effect. However, if someone were to click their browser's back button, they wouldn't go where they originally came from.
Thanks in advance. Any help would be useful...I don't know what this technique is called so google hasn't been really useful :(
Edit: based on responses, I found my question was solved here: How to use cursor() for pagination?
Look into query cursors. Thay are made to be serialized and sent to client, to be used in creating "next" and "previous" paging requests.
NOTE: don't use offset on queries. This can be VERY expensive, as it actually fetches (and charges) all entities up to offset+limit position, but returns to application only limit results.
I'm not sure that putting all the results as hidden content in the HTML and manipulating it using JS is a very good idea if you might have a large result set (think about what happened if Google used this approach). There's also the back functionality issue that you've mentioned.
So, as for querying a wanted "results page" each time, I think the Google's GQL Reference might help you, take a look specifically at the LIMIT clause, it can help you create the paging mechanism you're looking for by supplying it with the number of items-per-page you want as "count" and the numbers of items-previously-viewed as "offset" (0 at first call).
As for displaying, I think that the Google Images / Facebook News Feed approach might also be interesting to think about (loading on scroll instead of paging), but that's a matter of your personal choice :)
Hope this helps, good luck!
EDIT: After reading Peter's answer, I found it much more efficient to use cursors for pagination, a good reference is given in his answer.
I'd like to list all active products (from all or a specific category) in a template. I've looked almost everywhere and I simply cannot find a way to do this.
I want to display them in the footer of the shop (10 products from 1 category). That means show them without selecting product category.
Is this even possible? Products are only listed in the category template...
I'm using Satchmo 0.9.2
EDIT: Somehow I've missed this:
http://www.satchmoproject.com/docs/dev/customization.html
So it's solved...
Thank you!
this is a more general answer since there isnt any answer yet, so dont beat me. You also have to know that I never used satchmo, I never had a look at it.
But despite this, if I had to deal with your situation, I would have a look at the source code.
You might find answers there to develop something custom for your situation. This can be a tricky task but at least its worth a try.
There have to be models which store the data for your product and categories. Have a look at them and the views that retrieve the products from the database to render them. Also a look into the database cant hurt (think of phpmyAdmin to have a nice webbased interface).
It can be helpful to fire up your ./manage.py shell, import your/satchmos product and category models and play around with them.
A possible solution then could be to write a custom context_processor which retrieves the needed products/categories and passes these products from a category to your footer on a more global basis. Have a look here https://docs.djangoproject.com/en/1.3/ref/templates/api/#writing-your-own-context-processors. Maybe a custom middleware could also be a possibility. https://docs.djangoproject.com/en/dev/topics/http/middleware/#writing-your-own-middleware
I hope this helps. At least worth a try :)
I am listing products as table rows, each row contains input fields for specifying the quantity of products.
I made a Fiddle for it here, http://jsfiddle.net/kroofy/4jTa8/19/
As you can see, after the input in the Qty field have been made, the whole row render again. And because of that the focus of the input field will be lost, which is not good if you want to input more than just one digit, or tab between input fields.
What would be the most elegant way to solve this?
I would handle this by setting model.set({qty: _qty}, {silent: true}) and then updating the non-input fields with this.$.
As an alternative to the silent treatment: rather than listening for change events, listen for change:qty and change:sellPrice and have a method that updates just the HTML that needs updating within this.$, rather than re-rendering the DOM object and breaking your focus.
Either way, your comment about "selective updating" on the fiddle is certainly the right way to go.
(this.$ is a backbone hack to jQuery that restricts all selectors to search only within the DOM of the View's element. The element doesn't even need an ID or class; it just needs to exist and the View maintains a handle to it. It's incredibly useful.)
i built a plugin for backbone called Backbone.ModelBinding that may be able to help in this situation. my plugin allows you to update portions of a view with data from a model, when the model changes.
i've forked / updated your fiddle to show it in action: http://jsfiddle.net/derickbailey/FEcyF/6/
i removed the binding to the model change. i've also added id attributes to the inputs of the form to facilitate the plugin (the attribute that the plugin uses is configurable, though). and lastly, i've added a data-bind attribute to the sell price total td.
you can get the plugin here: http://github.com/derickbailey/backbone.modelbinding/
hope that helps
FWIW: my plugin is an automated version of what Elf is suggesting. I've written code exactly like he is describing, numerous times, which is where the plugin came from. I just got tired of writing that code by hand :)
Im looking to build a topic map to catagorize content.
For example the Topic 'Art' may have sub categories of 'Art History', 'Painting', 'Sculpture' etc etc.
I've crawled a few online resources, but I've hit a problem related to how I wish to use the hierarchy.
I've got a lot of content that I wish to index by topic. So to give the above example, if a user searches for 'Art' then they will not only get anything that mentions 'Art', but also anything that mentions 'Painting', even if it doesnt mention 'Art'. Fair enough.
But if, in another part of my heirarchy, I have 'House Maintenance', for example, then that might also have a subtopic of 'Painting'.
But then if a user searches for 'Art', my engine will say 'well, Painting is a sub category of 'Art', so I'll include this peice of content thats all about the best colour to paint your bathroom walls....
Has anyone come across this problem before? I've tried googling, but without knowing the exact terminology its hard to make headway....
EDIT: More succinctly, 'Painting' is a subtopic of 'Art', but if something is about 'Painting' then it doesnt neecssarily follow that its about 'Art', since 'Art' is not the only parent of 'Painting'.
In "topic maps", as it is understood in the related standard you can set different "scopes" to a topic. So "painting" may be part of two scopes, with different meanings.
A topic map:
http://www.ontopia.net/page.jsp?id=vizigator
Scope:
http://www.ontopia.net/topicmaps/materials/tao.html#stp-scope
If the Topic Map you are creating is built on Topic Maps technology, then subjectIdentifiers can be used to distinguish between two Topics with the same name (both named "Painting") that actually represent two different Subjects (Painting as an Art form, and Painting in the sense of home renovation).
If someone queries about Art and you drill down to Painting, then you can return only those entries related to 'Painting as an Art form' because those Painting entries are no longer thrown together on one heap.
Turning up late to this party (you've probably already built it or moved on or found an answer) but thought I'd throw in my 2 cents having worked on a high end Topic Map based CMS.
What you are missing out in your description is how topics are linked together. Topic are linked together via Associations that in themselves have Type's and Roles. So yes painting would be a child of art and of house maintenance but they would be linked differently.
Defining your type and role is up to you really, there is no hard and fast rules its really just down to your own leanings. So
Topic: Art
Association: Source=Art, Reference=Painitng, Type=Culture, Role=Practice
Topic: House Maintenance
Association: Soruce=House Maintenance, Reference=Painting, Type=DIY, Role=Activity
I suck at categorisation but hopefully you can see what I'm getting at. You'd filter your searches based on the type and role. So if someone searched for art you'd return painting and if you wanted to dig deeper and return co-related topics you are talking about returning Culture associated topics and not DIY associated topics.
Topic Maps if done right are extremely flexible, you've also got scope and language baked in too if you do it right. You should be able to link the same topics together in a 100 different ways and see the data differently depending on your starting point.
Information Architecture for the World Wide Web would give you a good start on organizing information... it's a good read, but might not be so technically detailed.
Since you want to process House/Painting and Art/Painting differently, then it seems like you'll need two distinct entries for Painting (one for each meaning). Which one you associate a given 'lump of text' with could be based on context clues from the text itself, if your text processor is powerful enough.
For example, whenever you have a conflict like this, look in the text - do you see other words there? Like 'sink', 'wall', 'hard wood', or 'windows'? Or do you see other terms like 'Monet', 'impressionism', 'canvas', and 'gallery'? That'll allow you to automate the decision, and should be fairly accurate. The only snag is that this presumes you have a fairly healthy dictionary of 'related terms' lying around somewhere.
On the user-end, when Painting is selected, you'd simply have to either merge all the results together, or present the user an option to select which parent topic they want to be viewing results from.
I don't know of a specific name for that, but I don't think it should really be a problem, either. All it calls for is that Art/Painting and House Maintenance/Painting are understood as separate entities. Someone searching for "art" gets subcategories of Art, so gets Art/Painting. Someone searching for "house maintenance" gets subcategories of House Maintenance, so gets House Maintenance/Painting. Someone searching for "painting" gets Art/Painting and House Maintenance/Painting, which is appropriate.