I have the string with html markup, an I want to cretae Doc elment from it like this:
Doc.FromHtm "<div><p>.....</p>.....</div>"
As I understand that this is not possible right now. Ok, what is not possible to accurately sew, I tried to roughly nail using jquery:
JQuery.JQuery.Of( "." + class'name ).First().Html(html'content)
But to call this code, I need to specify an event handler for the Doc element. But it is not implemented in UI.Next.
I tried to track changes of a model with a given CSS class asynchronously:
let inbox'post'after'render = MailboxProcessor.Start(fun agent ->
let rec loop (ids'contents : Map<int,string>) : Async<unit> = async {
// try to recive event with new portion of data
let! new'ids'contents = agent.TryReceive 100
// calculate the state of the agent
let ids'contents =
// merge Map's
( match new'ids'contents with
| None -> ids'contents
| Some (new'ids'contents) ->
new'ids'contents # (Map.toList ids'contents)
|> Map.ofList )
|> Map.filter( fun id content ->
// calculate CSS class name
let class'name = post'text'view'class'name id
// change it's contents of html
JQuery.JQuery.Of( "." + class'name ).First().Html(content).Size() = 0)
// accept the state of the agent
return! loop ids'contents }
loop Map.empty )
and then, for example for one element:
inbox'post'after'render.Post [id, content]
But it is too difficult, unreliable and not really working.
Please give me an idea how to solve the problem if possible. Thanks in advance!
Just in case someone needs to use static HTML in WebSharper on the server (I needed to add some javascript to the WebSharper generated HTML page), there is fairly new Doc.Verbatim usable e.g. like
let Main ctx action title body =
Content.Page(
MainTemplate.Doc(
title = title,
menubar = MenuBar ctx action,
body = body,
my_scripts = [ Doc.Verbatim JavaScript.Content ]
)
)
Already answered this on https://github.com/intellifactory/websharper.ui.next/issues/22 but copying my answer here:
If all you want is to create a UI.Next Doc from static html you can do the following:
let htmlElem = JQuery.JQuery.Of("<div>hello</div>").Get(0)
let doc = Doc.Static (htmlElem :?> _)
This is not very nice but should work and I don't think there's a better way to do it at the moment. Or maybe you could use templating but that's not documented yet and I'm not sure it would fit your use case.
Obviously if you want to change the rendered element dynamically you can make it a Var and use Doc.EmbedView together with Doc.Static.
Related
I want to get all the attributes from my "Actual Item Inventry" (From Stock Items Form) so i have:
PXResultset<CSAnswers> res = PXSelectJoin<CSAnswers,
InnerJoin<InventoryItem,
On<CSAnswers.refNoteID, Equal<Current<InventoryItem.noteID>>>
>
>.Select(new PXGraph());
But, this returns me 0 rows.
Where is my error?
UPDATED:
My loop is like this:
foreach (PXResult<CSAnswers> record in res)
{
CSAnswers answers = (CSAnswers)record;
string refnoteid = answers.RefNoteID.ToString();
string value = answers.Value;
}
... but i can not go inside foreach.
Sorry for the English.
You should use an initialized graph rather than just "new PXGraph()" for the select. This can be as simple as "this" or "Base" depending on where this code is located. There are times that it is ok to initialize a new graph instance, but also times that it is not ok. Not knowing the context of your code sample, let's assume that "this" and "Base" were insufficient, and you need to initialize a new graph. If you need to work within another graph instance, this is how your code would look.
InventoryItemMaint graph = PXGraph<InventoryItemMaint>.CreateInstance<InventoryItemMaint>();
PXResultset<CSAnswers> res = PXSelectJoin<CSAnswers,
InnerJoin<InventoryItem, On<CSAnswers.refNoteID, Equal<Current<InventoryItem.noteID>>>>>
.Select(graph);
foreach (PXResult<CSAnswers> record in res)
{
CSAnswers answers = (CSAnswers)record;
string refnoteid = answers.RefNoteID.ToString();
string value = answers.Value;
}
However, since you should be initializing graph within a graph or graph extension, you should be able to use:
.Select(this) // To use the current graph containing this logic
or
.Select(Base) // To use the base graph that is being extended if in a graph extension
Since you are referring to:
Current<InventoryItem.noteID>
...but are using "new PXGraph()" then there is no "InventoryItem" to be in the current data cache of the generic base object PXGraph. Hence the need to reference a fully defined graph.
Another syntax for specifying exactly what value you want to pass in is to use a parameter like this:
var myNoteIdVariable = ...
InventoryItemMaint graph = PXGraph<InventoryItemMaint>.CreateInstance<InventoryItemMaint>();
PXResultset<CSAnswers> res = PXSelectJoin<CSAnswers,
InnerJoin<InventoryItem, On<CSAnswers.refNoteID, Equal<Required<InventoryItem.noteID>>>>>
.Select(graph, myNoteIdVariable);
foreach (PXResult<CSAnswers> record in res)
{
CSAnswers answers = (CSAnswers)record;
string refnoteid = answers.RefNoteID.ToString();
string value = answers.Value;
}
Notice the "Required" and the extra value in the Select() section. A quick and easy way to check if you have a value for your parameter is to use PXTrace to write to the Trace that you can check after refreshing the screen and performing whatever action would execute your code:
PXTrace.WriteInformation(myNoteIdVariable.ToString());
...to see if there is a value in myNoteIdVariable to retrieve a result set. Place that outside of the foreach block or you will only get a value in the trace when you actually get records... which is not happening in your case.
If you want to get deep into what SQL statements are being generated and executed, look for Request Profiler in the menus and enable SQL logging while you run a test. Then come back to check the results. (Remember to disable the SQL logging when done or you can generate a lot of unnecessary data.)
How would I go about changing the default MCheckBox state text (currently I/0) to, for example, YES/NO or ON/OFF?
Mr. Daniel Kurka is the author for all the widget classes in MGWT. If the look & feel is not
fulfilling our requirement, We can edit those classes and rewrite them according to our requirement.Because they are open source. I done this on many classes like CellList,FormListEntry and MCheckBox. code for ON/OFF instead of I/O
public MyOwnCheckBox(CheckBoxCss css) {
this.css = css;
css.ensureInjected();
setElement(DOM.createDiv());
addStyleName(css.checkBox());
onDiv = DOM.createDiv();
onDiv.setClassName(css.on());
onDiv.setInnerText("ON");
getElement().appendChild(onDiv);
middleDiv = DOM.createDiv();
middleDiv.setClassName(css.middle());
Element middleContent = DOM.createDiv();
middleContent.setClassName(css.content());
middleDiv.appendChild(middleContent);
getElement().appendChild(middleDiv);
offDiv = DOM.createDiv();
offDiv.setClassName(css.off());
offDiv.setInnerText("OFF");
getElement().appendChild(offDiv);
addTouchHandler(new TouchHandlerImplementation());
setValue(true, false);
}
Write a new class like MyOwnCheckBox.just copy the code in MCheckBox and paste in your class MyOwnCheckBox, find and replace the MCheckBox with MyOwnCheckBox in the code(change constructor's name). do the following changes.
onDiv.setInnerText("ON");
offDiv.setInnerText("OFF");
and finally create object to MyOwnCheckBox rather MCheckBox, it'll shows MCheckBox with ON/OFF.
Right now there is no way to do that, but there is no real reasons that checkbox does not implement HasText other than we might need to update the css so that big text will not break the layout.
If you think mgwt should implement this go and vote for this issue: http://code.google.com/p/mgwt/issues/detail?id=171
Well, an easy way to accomplish the same thing, without creating a new class that mimics MCheckBox, is to do something like the code below:
CheckBoxCss css = MGWTStyle.getTheme().getMGWTClientBundle().getCheckBoxCss();
String offClass = css.off();
String onClass = css.on();
NodeList<Node> checkBoxElems;
mIsSingleSkuBox = new MCheckBox(css);
checkBoxElems = mIsSingleSkuBox.getElement().getChildNodes();
for( int i = 0; i < checkBoxElems.getLength(); i++ )
{
Element openElem = (Element) checkBoxElems.getItem(i);
String className = openElem.getClassName();
if( className.equals( offClass))
{
openElem.setInnerText("No" );
}
else if( className.equals( onClass))
{
openElem.setInnerText("Yes" );
}
}
It will probably have space problems with anything longer than 3 characters, but it works consistently with "Yes" and "No" for me.
In a controller for a page in tornado-cms, I do the following:
def res = Service.tornado.articles([ articleCategoryPath: "boker/ny"]);
Service.tornado.loadFullArticles(res);
res.sort { a,b ->
b.props.year <=> a.props.year
}
tornado.small_articles = res;
Or, shorter:
tornado.small_articles = Service.tornado.articles([
articleCategoryPath: "boker/ny",
full: true ])
.sort { a, b -> b.props.year <=> a.props.year };
This fills the content box small_articles with the all the articles from a specific folder "boker/ny" reversely sorted by the article prop year.
It works fine, but is it possible to save the changes made to the content box tornado.small_articles so that the resulting list of articles is also visible from the GUI? Something like Service.tornado.saveChangesToPageContentBox(page, content_box_nr, tornado.small_articles);?
Start by removing the articles currently bound to the small_articles box like this:
Integer containerId = <id-of-small-articles-container>;
Service.tornado.getPageBindings(page.id).each { binding ->
if (binding.containerId == containerId)
Service.tornado.deletePageBinding(binding);
}
Then add new bindings for the articles you have collected:
tornado.small_articles.each {
Service.tornado.addPageBinding(new ArticlePageContainer(page.id, it.id, containerId));
}
You should not do this on every request to the given page, but rather update the list when the content changes or by some other, less frequent criteria.
I am writing velocity templates for my liferay theme and I am wondering, whether it is possible to create a new object inside the velocity template.
The reason is that in liferay there is no contextTool registered in the context and I really want to be able to inspect the variables that are present in the template at a given time.
There is a cool macro for this, but unfortunately it uses the contexttool.
I'd like to do something like:
#set($contextTool = new ContextTool())
Another solution would be java code that is provided with the liferay theme that is able to add stuff in the template context. But I don't know how this would work either... ;-)
try with
#set($contextTool = $portal.getClass().forName("full.package.ContextTool").newInstance())
EDIT
IF I understood you than this should give you what you want
#set($ve = $serviceLocator.findService("com.liferay.portal.kernel.velocity.VelocityEngine"))
#set($wvc = $ve.getWrappedStandardToolsContext().getWrappedVelocityContext())
#set($cVE = $portal.getClass().forName("org.apache.velocity.app.VelocityEngine"))
#set($cHSREQ = $portal.getClass().forName("javax.servlet.http.HttpServletRequest"))
#set($cHSRES = $portal.getClass().forName("javax.servlet.http.HttpServletResponse"))
#set($cSC = $portal.getClass().forName("javax.servlet.ServletContext"))
#set($cCC = $portal.getClass().forName("org.apache.velocity.tools.view.context.ChainedContext"))
#set($cVEI = $portal.getClass().forName("com.liferay.portal.velocity.VelocityEngineImpl"))
#set($cC = $portal.getClass().forName("org.apache.velocity.context.Context"))
#set($cVEU = $portal.getClass().forName("com.liferay.portal.kernel.velocity.VelocityEngineUtil"))
#set($ve = $cVEU.getMethod("getVelocityEngine").invoke(null))
#set($fVE = $cVEI.getDeclaredField("_velocityEngine"))
$fVE.setAccessible(true)
#set($cc = $cCC.getConstructor($cC, $cVE, $cHSREQ, $cHSRES, $cSC).newInstance($wvc, $fVE.get($ve), $request, $response, $request.getSession().getServletContext()))
#set($contextTool = $portal.getClass().forName("org.apache.velocity.tools.view.tools.ContextTool").newInstance())
$contextTool.init($cc)
After that you can use, for example
$contextTool.getKeys()
If this is not what you need, let me know ...
Today, I'm having a problem is after I had created a Calculated field. It seems there is no way to add AllContentTypes. And the DefaultView, maybe I can handle this. And I also saw this method:
spList.Fields.AddFieldAsXml(spFieldUser.SchemaXml, True, SPAddFieldOptions.AddToAllContentTypes);
But in this case, I'm not sure I can use it or not. Because my code is:
//SPField tempSPField = spList.Fields.CreateNewField(createSPColumnObject.ColumnType, createSPColumnObject.ColumnName);//We can not use this code line for creating Calculated (there is no constructor for this)
SPFieldCollection collFields = spList.Fields;
string strSPFieldCalculatedName = collFields.Add(createSPColumnObject.ColumnName, SPFieldType.Calculated, false);
if (createSPColumnObject.IsAddedToDefaultView)
{
SPView spView = spList.DefaultView;
spView.ViewFields.Add(strSPFieldCalculatedName);
spView.Update();
}
SPFieldCalculated spFieldCalculated = null;
//
spFieldCalculated = (SPFieldCalculated)collFields[createSPColumnObject.ColumnName];
spFieldCalculated.ShowInDisplayForm = true;
//spFieldCalculated.ShowInEditForm = true;
spFieldCalculated.ShowInListSettings = true;
//spFieldCalculated.ShowInNewForm = true;
spFieldCalculated.ShowInViewForms = true;
//
spFieldCalculated.Description = createSPColumnObject.ColumnDescription;
spFieldCalculated.Formula = string.Format(#"={0}",createSPColumnObject.CalcFormula);
spFieldCalculated.Update();
//spList.Fields.AddFieldAsXml(spFieldCalculated.SchemaXml, createSPColumnObject.IsAddedToDefaultView, SPAddFieldOptions.AddToAllContentTypes);// also use this code line because we will get an exception with a duplicate column ID.
spFieldCalculated.OutputType = SPFieldType.Text;
spList.Update();
I totally created a Calculated column but how can I add it to allcontent types ? everybody could help me out this ? BTW, to the DefaultView, I did like the above is right ? Could eveybody let me know this ?
I just worry about everybody get misunderstanding ? Or review with missing code. So could everybody please to take a look on my code clearly ? Thanks all.
Many thanks, :)
Standley Nguyen
I'm not sure if i fully understand what you are trying to do however i may be able to shed some light on some parts of what you are trying to do.
When you create your field does it then appear in your site actions -> site settings -> Site columns. If so you have created this correctly. If it doesn't there are hundreds of examples of how to do this if you search google.
Once you have your field create you then need to consider which content types you want to add it to. Once you have these content types you then have to add something called a field link to the Content type.
This isn't my code i have picked it off the web but this should do what you require.
SPContentType ct = web.ContentTypes[contentType];
ct.FieldLinks.Add(new SPFieldLink(field));
ct.Update();
Cheers
Truez