CheckBoxListView checked all elements - gxt

i'm using gxt CheckBoxListView
CheckBoxListView<BaseModel> checkList = new CheckBoxListView<BaseModel>();
checkList.setStore(store);
i want to setChecked(true) for all the models in the store
is there a easy way to do that

For all the models present in your store (assuming that you have done store.addAll(List yourList);...), set the checked property to "true"
for(ModelData m : store.getModels()) {
checkList.setChecked(m,true);
}

Related

NODE.JS: iterating over an array of objects, creating a new key if it does not exist

I am iterating over a collection of data, in my case, an array of objects. Here is a sample of 2 data points from it:
{
violation_id: '211315',
inspection_id: '268804',
violation_category: 'Garbage and Refuse',
violation_date: '2012-03-22 0:00',
violation_date_closed: '',
violation_type: 'Refuse Accumulation' },
{
violation_id: '214351',
inspection_id: '273183',
violation_category: 'Building Conditions',
violation_date: '2012-05-01 0:00',
violation_date_closed: '2012-04-17 0:00',
violation_type: 'Mold or Mildew' }
I need to create a new array of objects from this, one for each "violation_category" property. If Violation category already exists in the new array I am creating, i simply add the information to that existing category object (instead of having two "building conditions" objects for example, I would just add to an existing one).
However, I am having trouble assigning to the existing object if the current one exists (it's easy to check if it does not, but not the other way around). This is what am attempting to do currently:
if (violationCategory.uniqueCategoryName) {
violationCategory.uniqueCategoryName.violations = results[i].violation_id;
violationCategory.uniqueCategoryName.date = results[i].violation_date;
violationCategory.uniqueCategoryName.closed =
results[i].violation_date_closed;
} else {
category.violations = results[i].violation_id;
category.date = results[i].violation_date;
category.closed = results[i].violation_date_closed;
violationCategory.push(category);
}
In first condition, if this category (key) exists, I simply add to it, and in the second condition, this is where I am struggling. Any help appreciated. Thanks guys.
Just add an empty object to the key if there no object there :
violationCategory.uniqueCategoryName = violationCategory.uniqueCategoryName || {};
And only then, add the data you want to the object.
violationCategory.uniqueCategoryName.violations = results[i].violation_id;
violationCategory.uniqueCategoryName.date = results[i].violation_date;
violationCategory.uniqueCategoryName.closed =
results[i].violation_date_closed;
No condition needed.
Good luck!
Assuming that you have an input variable which is an array of objects, where the objects are looking like the objects of the question, you can generate your output like this:
var output = {};
for (var item of input) {
if (!output[item.violation_category]) output[item.violation_category] = [];
output[item.violation_category].push(item);
}
Of course you might customize it like you want.

Generate Wagtail Field's using a FOR loop

I am new to Wagtail and want to create several Field's in my models.py by iterating over a list of names like this ...
class HomePage(Page):
myFields = [ ('paragraph', blocks.RichTextBlock(classname="oneA")),('image', ImageChooserBlock()) ]
mySections = ['sectionOne', 'sectionTwo', 'sectionThree']
for mySection in mySections:
mySection = StreamField(myFields,null=True,blank=True)
content_panels = Page.content_panels + [
StreamFieldPanel('sectionOne'), StreamFieldPanel('sectionTwo'), StreamFieldPanel('sectionThree'),
]
This produces an error message ...
django.core.exceptions.FieldDoesNotExist: HomePage has no field named 'sectionOne'
Is there a way of doing this, or do I have to declare each one individually like so:
sectionOne = StreamField(myFields,null=True,blank=True)
This doesn't work because mySection = StreamField(...) is just repeatedly defining a field called mySection - there's no way for Python to know that you want to define a field with the name currently given in mySection.
I think the only way to achieve this is to set the fields up in a metaclass, which will almost certainly be more complex and less readable than just repeating the line. See How to dynamically set attributes to a class in models in Django?, Dynamically create class attributes

How do you set the value of 'DocumentShowInSiteMap' property in Kentico?

How do you set the value of DocumentShowInSiteMap property in Kentico?
I've tried:
Using the DocumentHelper and TreeHelper apis but with both, this property doesn't give you access to the setter.
Tried running a SQL Query setting the value of dbo.CMS_Document.DocumentShowInSiteMap to 1 and 0. These queries run fine but when I go to the pages app, there is no change in the 'Show in sitemap' property checkbox, ie. setting the database field to 0 doesn't 'untick' this checkbox.
I'm trying to run a scheduled task which will set this property for documents at a specified location automatically. What is the proper way to do this? Any help appreciated.
Have you tried this?
int TheDocumentToModify = 1221;
var PageItem = DocumentHelper.GetDocument(TheDocumentToModify , new TreeProvider());
foreach(var culturePage in PageItem.CultureVersions)
{
culturePage.SetValue("DocumentShowInSiteMap", true);
// May need to apply Workflow check in / check out, see Kentico API examples based on your need.
culturePage.Update();
}
Within code, there is no simple way. Setter should be available within special class DocumentCultureDataInfo and it should be saved with SetObject. This class contains all of culture DB fields and is manipulated by DocumentCultureDataInfoProvider.
This class is an internal property of TreeNode. However I have not tried doing this arbitrary in code and mentioned classes are part of innner API.
Your second approach should work, but documents and their properties are cached and you will need to refresh cache so that new DB value is actually picked up Loading of this property goes through simple GetData in LoadDefaultValues for each TreeNode.
Trevor J Fayas's answer would probably work. I figured this out yesterday and just leaving my solution here just in case:
TreeHelper
.GetDocuments(task.CurrentSiteName, aliaspath, null, false, "", "", "", -1, false, -1)
.Where(doc => doc.DocumentShowInSiteMap)
.ToList()
.ForEach(node =>
{
node.SetValue("DocumentShowInSiteMap", false);
node.Update();
});
Obviously replace aliaspath with the one you need or use DocumentHelper.GetDocuments which takes different parameters.

Can't set Orchard field values unless item already created

I seem to be having a problem with assigning values to fields of a content item with a custom content part and the values not persisting.
I have to create the content item (OrchardServices.ContentManager.Create) first before calling the following code which modifies a field value:
var fields = contentItem.As<MyPart>().Fields;
var imageField = fields.FirstOrDefault(o => o.Name.Equals("Image"));
if (imageField != null)
{
((MediaLibraryPickerField)imageField).Ids = new int[] { imageId };
}
The above code works perfectly when against an item that already exists, but the imageId value is lost if this is done before creating it.
Please note, this is not exclusive to MediaLibraryPickerFields.
I noticed that other people have reported this aswell:
https://orchard.codeplex.com/workitem/18412
Is it simply the case that an item must be created prior to amending it's value field?
This would be a shame, as I'm assigning this fields as part of a large import process and would inhibit performance to create it and then modify the item only to update it again.
As the comments on this issue explain, you do need to call Create. I'm not sure I understand why you think that is an issue however.

Yii Lazy Loading From Object Instance ($this) with Criteria (Is it possible?)

I'm new to Yii and used to Kohana. I have two models:
1. sampleRequests -> (this has many SampleShares)
2. sampleShares
In my case I have already instantiated an object (sampleRequest) and I am trying to get a particular sampleShares based on added criteria.
In Kohana I could do:
$myShare = $this->sampleShares->where('user_id','=',$my_user_id)->find();
It Yii I have tried something similar:
$myShare = $this->sampleShares->find(array(
'condition'=>'user_id:user_id',
'params'=>array(':user_id'=>$my_user_id)));
The previous does not work for me however, the following will work:
$myShare = SampleShare::model()->find(array(
'condition'=>'sample_id=:id AND user_id=:user_id',
'params'=>array(':id'=>$this->id, ':user_id'=>Yii::app()->user->id)));
So my question is, can you grab related models with appended select criteria to the relationships established in Yii (particular with the instance or $this)? (Similar to my Koahana example?) If so how do you do that?
$myShare = SampleShare::model()->findAll(array('condition'=>'sample_id='.$id.' AND user_id='.$user_id));
and relation query example
$myShare = SampleShare::model()->with('sampleRequests')->findAll(array('condition'=>'sample_id='.$id.' AND user_id='.$user_id));
you can find the realtion name in your model file...
And then you can get the related table records using $myShare->sampleRequests
you can set relationship between the tables in your model file, like this:
public function relations()
{
return array(
'category' => array(self::BELONGS_TO, 'CategoryCategory', 'category_id'),
);
}
how to use:
$model=Blog::model()->with('category')->findAll(); //object
Nevermind I figured it out. I just had to replace:
$this->sampleShares->find(
with
$this->with('sampleShares')->find(

Resources