I have been working on Seaside 3.1 for a couple of days and I'm trying to design a simple TicTacToe with Ajax.
It works great without ajax with this code:
renderContentOn: html
html heading: 'Tictactoe'.
html
form: [
1 to: 3 do: [ :row |
1 to: 3 do: [ :col |
html imageButton
url: (tictactoe imageCase: row * 10 + col);
callback: [ tictactoe playsX: row playsY: col ] ].
html break ] ]
and with ajax it doesn't work at all, though the page doesn't refresh as expected. The imageButton never changes for a simple image with another url.
The goal is just to swap the imageButton for an image with another url when I click on it.
Here's where I am with my code:
renderContentOn: html
html heading: 'Tictactoe'.
1 to: 3 do: [ :row |
1 to: 3 do: [ :col |
html imageButton
url: (tictactoe imageCase: row * 10 + col);
id: 'case' , row asString , col asString;
onClick:
(html scriptaculous updater
id: 'case' , row asString , col asString;
callback: [ :r |
tictactoe playsX: row playsY: col.
r render: (html image url: (tictactoe imageCase: row * 10 + col)) ];
return: false) ].
html break ]
I am new and not very good with this technology, therefore I am ready to hear any answer, advice or guidance.
I would like to thank you in advance, have a good day.
My first suggestion would be to drop Scriptaculous and use JQuery instead, the former isn't developed anymore while JQuery is maintained daily and is supported by Seaside as well.
renderContentOn: html
html heading: 'Tictactoe'.
1 to: 3 do: [ :row |
1 to: 3 do: [ :col |
html imageButton
id: 'case' , row asString , col asString;
url: (tictactoe imageCase: row * 10 + col);
onClick:
(html jQuery ajax
callback: [ tictactoe playsX: row playsY: col ];
script: [ :s |
s
<<
((html jQuery id: 'case' , row asString , col asString)
replaceWith: [ :h |
h image url: (tictactoe imageCase: row * 10 + col) ]) ])].
html break ]
The key is in the onClick: handler, where you pass a JQuery Ajax object that executes a callback on the server and then returns a script (JS) whose content have the instructions to replace an element with certain id (an imageButton with id 'case' , row asString , col asString) by what is rendered by the replaceWith: render block..
You can even go a little further and merge both the callback: and script: into a single call as follows:
onClick:
(html jQuery ajax
script: [ :s |
tictactoe playsX: row playsY: col.
s << ((html jQuery id: 'case' , row asString , col asString)
replaceWith: [ :h |
h image url: (tictactoe imageCase: row * 10 + col) ]) ])].
Related
first of all, excuse me if my english is not always very good.
I have a problem with the each_with_index... When I show a project, I display the offers for this project. I have to make appear a banner in third position of offers, so I use each_with_index for that.
The problem is that: if I have sixteen offers on a project, I have sixteen times the entirely list of offers, and I don't know why.
This is my code:
- #offers.each_with_index do |offer, index|
- if !user_signed_in? && (#project.published? || #project.pending_attribution?)
- if #offers.size >= 3 && index == 3
= render 'offer_cta'
- contact_bloc = user_contact_bloc(offer.user, viewer: current_user, display_contact_info: offer.display_contact_info?)
.card.offer-card.mt-4[offer]{ class: offer_class(offer) }
.card-header.d-flex.justify-content-between.align-items-center.border-bottom-0
.offer-date
%span.text-muted
Offer filed on
= l(offer.created_at, format: '%d/%m/%Y à %Hh%M')
- if user_signed_in? && current_user.admin? && !offer.user.suspended_at.nil?
... exctera
Also, if I try this in my console, I don't have any problem...
Have you ever had this problem?
Don't hesitate to ask me if you need more information.
EDIT :
This is the code in my render 'offer_cta', a very basic code:
.row
.col-md-12
.project-cta.p-5.mb-2.text-center
%h5
%strong
blabla
%p.text-muted blablabla
%p.m-0
= link_to "Send a quote", "", class: "btn btn-primary px-3", data: { toggle: 'modal', target: '#modal-sign' }, onclick: "ga('send', 'event', 'button', 'Clic', 'Sign up');", tabindex: -1
#offers initialization:
#offers = #project.offers_accessible_by(current_ability, current_user)
#offers.mark_as_read_for(current_user)
#offers = #offers.includes(:offer_interactions, user: [:user_profile, :user_subscription, :user_contact])
I'm working on a spree commerce application. I have troubles with product filters. I can edit range filters but i want to add "all prices" filter.
Here is the code:
conds = [ [ Spree.t(:or_over_price, price: format_price(0)) , v[:amount].gteq(0)],
[ "#{format_price(25000)} - #{format_price(50000)}" , v[:amount].in(25000..50000)],
[ "#{format_price(50000)} - #{format_price(75000)}" , v[:amount].in(50000..75000)],
[ "#{format_price(75000)} - #{format_price(100000)}" , v[:amount].in(75000..100000)]]
{
So is working as 0 or over. But i want to show it as "all prices"
I need to change this line but i dont know how:
[ Spree.t(:or_over_price, price: format_price(0)) , v[:amount].gteq(0)]
Thanks in advance.
Just add to your config/locales/en.yml
all_prices: all prices
then in your conds array
conds = [ [ Spree.t(:all_prices) , v[:amount].gteq(0)],
[ "#{format_price(25000)} - #{format_price(50000)}" , v[:amount].in(25000..50000)],
[ "#{format_price(50000)} - #{format_price(75000)}" , v[:amount].in(50000..75000)],
[ "#{format_price(75000)} - #{format_price(100000)}" , v[:amount].in(75000..100000)]]
{
I'm trying to build a tree/outliner like graphical interface in Pharo/Smalltalk using Moose Glamorous Toolkit. So, far I have got this mockup:
Outliner mockup http://www.enlightenment.org/ss/e-53e3dee6777744.68598023.jpg
For that I'm using the following code:
| browser mainTree |
mainTree := UbakyeNode new.
mainTree becomeDefaultTree.
browser := GLMTabulator new.
browser
column: #tree;
column: [ :c |
c
row: #body;
row: #plugins ].
(browser transmit)
to: #tree;
andShow: [ :a |
(a tree)
title: mainTree header;
children: [ :eachNode |
eachNode children. ] "Children must return a collection" ].
(browser transmit)
to: #body;
from: #tree;
andShow: [ :a | a text title: 'Cuerpo | Body ' ].
(browser transmit)
to: #plugins;
from: #tree port: #selectionPath;
andShow: [ :a | a text title: 'Plugins | Extensiones' ].
browser openOn: mainTree children.
So I have now a browser which shows a tree made of UbakyeNodes (a tree like data structure I defined), but I would like not to show the Ubakye Nodes, but the titles of each node (headers) and the contents (bodies) of them when selected. With the help of the Pharo/Moose community I have understood that I need to pass the collection of all children (not just the headers of them), but I don't know who to sellect something particular in that collection to be shown on the browser, like headers of nodes in the #tree panel or bodies in the #body panel.
I would like to change also the size of each panel to be more like the shown in the screenshot, instead of the default one and be relative to window size. Is this possible?
Ok, thanks to Peter Kenny in the Pharo-users Community mailing list, now I have the answer. The issue is related with the "format:" keyword message, which was missing. Using it, is possible to tell Moose/Pharo how to display information taken from the children. Here is the modified working code:
| browser mainTree |
mainTree := UbakyeNode new.
mainTree becomeDefaultTree.
browser := GLMTabulator new.
browser
column: #tree;
column: [ :c |
c
row: #body;
row: #plugins ].
(browser transmit)
to: #tree;
andShow: [ :a |
(a tree)
title: mainTree header;
children: [ :eachNode |
(eachNode children) isNil
ifTrue: [ #() ]
ifFalse:[ eachNode children ] ];
format:[:eachNode |
(eachNode header) isNil
ifTrue: [ '' ]
ifFalse: [ eachNode header ] ].
"Children must return a collection" ].
(browser transmit)
to: #body;
from: #tree;
andShow: [ :a |
(a text)
title: 'Cuerpo | Body ';
format:[:eachNode |
(eachNode body) isNil
ifTrue: [ '' ]
ifFalse: [ eachNode body ] ]
].
(browser transmit)
to: #plugins;
andShow: [ :a | a text title: 'Plugins | Extensiones' ].
browser openOn: mainTree children.
And setting the relative width and height you do by using
row: #result span: 2;
for the row/column that should be twice as wide. So something like
browser
column: #tree;
column: [ :c |
c row: #body span: 3;
row: #plugins ] span: 3.
I am working with Spec library in Pharo 3 and I have found no way to add a header to a multi column list. However, adding headers is feasible through TreeColumnModel and TreeModel like this:
| m col1 col2 |
m := TreeModel new.
m roots: #(#a #b #c #d).
m rootNodeHolder: [ :item |
TreeNodeModel new
content: item;
icon: Smalltalk ui icons smallConfigurationIcon ].
m openWithSpec.
col1 := TreeColumnModel new
displayBlock: [ :node | node content asString ];
headerLabel: 'Character'.
col2 := TreeColumnModel new
displayBlock: [ :node | (Character value: node content asString first asciiValue + 1) asString ];
headerLabel: 'Character +1';
headerIcon: Smalltalk ui icons smallBackIcon.
m
columns: {col1. col2};
acceptDropBlock: [ :transfer :event :source :receiver | self halt ].
col2
headerLabel: 'Character +2';
headerIcon: Smalltalk ui icons smallBackIcon;
displayBlock: [ :node | (Character value: node content asString first asciiValue + 2) asString ].
m rootNodeHolder: [ :item |
TreeNodeModel new
content: (Character value: (item asString first asciiValue + 5)) asSymbol;
icon: Smalltalk ui icons smallFullscreenIcon ].
How could I get a header in the following MultiColumnListModel?
MultiColumnListModel new
items: {$a. $b. $c. $d. $f.};
displayBlock: [:e | {e asString. e isVowel asString} ];
openWithSpec.
Will this work for you?
model := MultiColumnListModel new
items: { {'Letter'. 'isVowel'.}. $a. $b. $c. $d. $f.};
displayBlock: [:e |
e isArray
ifTrue:[{e first asString. e last asString} ]
ifFalse:[
{e asString. e isVowel asString} ]].
model
whenSelectionChanged:[
model getIndex = 1 ifTrue:[
model setIndex:0].
];
openWithSpec.
How hide symbol in joomla paging ?
Example << Start < Prev 1 2 3 4 5 Next > End >>
I want to delete << <>>> so result is Start Prev 1 2 3 4 5 Next End
How to do that ?
If you don't like core hacks, you could create simple js script using mootools:
window.addEvent('load', function() {
$$('ul.pagenav a').each(function(el){
var text = el.getFirst().get('html');
text = text.replace('<','');
text = text.replace('>','');
text = text.replace('\u00AB','');
text = text.replace('\u00BB','');
el.getFirst().set('html',text);
});
});