Difference between revisions of "Folder Style assigned by metadata"

From OpenKM Documentation
Jump to: navigation, search
Line 6: Line 6:
 
* Property group ( metadata )
 
* Property group ( metadata )
 
* Folder Style icon ( Red / Green / Yellow with id values 18, 19, 20)
 
* Folder Style icon ( Red / Green / Yellow with id values 18, 19, 20)
 +
* Automation based on property group change
  
Property group:
+
 
 +
'''Property group:'''
 
<source lang="xml">
 
<source lang="xml">
 
<property-group label="Invoice status" name="okg:invoice">
 
<property-group label="Invoice status" name="okg:invoice">
Line 16: Line 18:
 
</select>
 
</select>
 
</property-group>
 
</property-group>
 +
</source>
 +
 +
 +
'''Code:'''
 +
<source lang="java">
 +
import com.openkm.api.OKMPropertyGroup;
 +
import com.openkm.bean.PropertyGroup;
 +
import com.openkm.api.OKMRepository;
 +
import com.openkm.bean.form.FormElement;
 +
import com.openkm.bean.form.Select;
 +
import com.openkm.bean.form.Option;
 +
import com.openkm.api.OKMFolder;
 +
 +
//String uuid = "e0ad61e4-2c2d-429e-aa00-27afa674551d";
 +
String path = OKMRepository.getInstance().getNodePath(null, uuid);
 +
String grpName = "okg:invoicedata";
 +
boolean hasGroup = false;
 +
for (PropertyGroup pg : OKMPropertyGroup.getInstance().getGroups(null, path)) {
 +
if (pg.getName().equals(grpName)) {
 +
hasGroup = true;
 +
}
 +
}
 +
if (hasGroup) {
 +
for (FormElement formElement : OKMPropertyGroup.getInstance().getProperties(null, path, grpName)) {
 +
if (formElement instanceof Select) {
 +
Select select = (Select) formElement;
 +
for (Option option : select.getOptions()) {
 +
if (option.isSelected()) {
 +
String fldPath = path.substring(0,path.lastIndexOf("/"));
 +
String fldUuid = OKMRepository.getInstance().getNodeUuid(null, fldPath);
 +
if (option.getValue().equals("open")) {
 +
OKMFolder.getInstance().setStyle(null, fldUuid, 19);
 +
} else if (option.getValue().equals("review")) {
 +
OKMFolder.getInstance().setStyle(null, fldUuid, 20);
 +
} if (option.getValue().equals("closed")) {
 +
OKMFolder.getInstance().setStyle(null, fldUuid, 18);
 +
}
 +
}
 +
}
 +
}
 +
}
 +
}
 +
 
</source>
 
</source>
  

Revision as of 19:22, 14 September 2013

Contents

The script assign folder style to folder based in database metadata values present into document contents into.

Description:

  • Property group ( metadata )
  • Folder Style icon ( Red / Green / Yellow with id values 18, 19, 20)
  • Automation based on property group change


Property group:

<property-group label="Invoice status" name="okg:invoice">
<select label="Status" name="okp:invoice.status" type="simple">
	<option label="Open" value="open" />
	<option label="Pending to review" value="review" />
	<option label="Closed" value="closed" />
</select>
</property-group>


Code:

import com.openkm.api.OKMPropertyGroup;
import com.openkm.bean.PropertyGroup;
import com.openkm.api.OKMRepository;
import com.openkm.bean.form.FormElement;
import com.openkm.bean.form.Select;
import com.openkm.bean.form.Option;
import com.openkm.api.OKMFolder;

//String uuid = "e0ad61e4-2c2d-429e-aa00-27afa674551d";
String path = OKMRepository.getInstance().getNodePath(null, uuid);
String grpName = "okg:invoicedata";
boolean hasGroup = false;
for (PropertyGroup pg : OKMPropertyGroup.getInstance().getGroups(null, path)) {
	if (pg.getName().equals(grpName)) {
		hasGroup = true;
	}
}
if (hasGroup) {
	for (FormElement formElement : OKMPropertyGroup.getInstance().getProperties(null, path, grpName)) {
		if (formElement instanceof Select) {
			Select select = (Select) formElement;
			for (Option option : select.getOptions()) {
				if (option.isSelected()) {
					String fldPath = path.substring(0,path.lastIndexOf("/"));
					String fldUuid = OKMRepository.getInstance().getNodeUuid(null, fldPath);
					if (option.getValue().equals("open")) {
						OKMFolder.getInstance().setStyle(null, fldUuid, 19);
					} else if (option.getValue().equals("review")) {
						OKMFolder.getInstance().setStyle(null, fldUuid, 20);
					} if (option.getValue().equals("closed")) {
						OKMFolder.getInstance().setStyle(null, fldUuid, 18);
					}
				}
			}
		}
	}
}

Example

Register database metadata values:

Okm user guide 498.png