'subclassing' content types

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

'subclassing' content types

Arjen
Hi,

Does anybody know if it's possible to create sub types of content, or like 'subclass' content types?
I'd like to be able to create a content type, let's say 'product' and then create two sub types called 'garden product' and 'kitchen product'.

Then I'd like to be able to create a relationship between some other object and a product, where that product could be of any product sub type, so either garden or kitchen.

Is that something that can be done?

If not then I guess I could get away with conditional fields of a content type.
Take for example the same 'product' object but then give it a 'type' property with a radio button value and different fields become available depending on the selected type.
I'm not sure if that's something that's usually done though.

Has anybody else come across these scenarios before?

Arjen 

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/59ddbb94-eec2-4662-9809-706d7b88eae9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: 'subclassing' content types

Arjen
Just to clarify, I have read this older thread from 2014 about the same subject, so I guess the main question is whether any new features have been added since to add this functionality?

Also, in post #2 it's suggested to use Javascript to show/hide fields dynamically.
Would anyone have any pointers how to do this, e.g. where to add the script etc?

Thanks



On Thursday, August 10, 2017 at 12:46:17 PM UTC+1, Arjen wrote:
Hi,

Does anybody know if it's possible to create sub types of content, or like 'subclass' content types?
I'd like to be able to create a content type, let's say 'product' and then create two sub types called 'garden product' and 'kitchen product'.

Then I'd like to be able to create a relationship between some other object and a product, where that product could be of any product sub type, so either garden or kitchen.

Is that something that can be done?

If not then I guess I could get away with conditional fields of a content type.
Take for example the same 'product' object but then give it a 'type' property with a radio button value and different fields become available depending on the selected type.
I'm not sure if that's something that's usually done though.

Has anybody else come across these scenarios before?

Arjen 

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/1fee58b7-dfae-486b-ad9a-15987d453cf1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: 'subclassing' content types

Xander
Hi Arjen,

I've copy-pasted some code from a macro we used to hide fields based on certain settings. I think this is the main code:

<script>
  dojo.require("dojo.NodeList-traverse");
    document.getElementById('$!{field}_tag').parentNode.style.display = 'none';
</script>

Here "field" is the field id you want to hide. You can use velocity/javascript to read other fields to determine what kind of "product" you are working with and which fields you need to hide.
Note that this is "hiding for convenience". You would need a Hook to prevent users from altering fields that they should not be able to alter.

Kind regards,

Xander

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/8d86c475-dd84-43d5-ba22-ddc93142cc9f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: 'subclassing' content types

Arjen
Thanks Xander,

What do you think would be the easiest way to apply this?
Would it be a good idea to make the dropdown or radio button group a custom component with this (or similar) javascript embedded or is there a different way?

Thanks
Arjen


On Thursday, August 10, 2017 at 1:14:49 PM UTC+1, Xander Steinmann wrote:
Hi Arjen,

I've copy-pasted some code from a macro we used to hide fields based on certain settings. I think this is the main code:

<script>
  dojo.require("dojo.NodeList-traverse");
    document.getElementById('$!{field}_tag').parentNode.style.display = 'none';
</script>

Here "field" is the field id you want to hide. You can use velocity/javascript to read other fields to determine what kind of "product" you are working with and which fields you need to hide.
Note that this is "hiding for convenience". You would need a Hook to prevent users from altering fields that they should not be able to alter.

Kind regards,

Xander

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/b5694663-9a7f-4785-b794-59d68a58be48%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: 'subclassing' content types

Mark Pitely
In reply to this post by Xander
Arjen,

With the advent of the API, you can pretty much do anything you want- you are free from having to use the dotCMS backend to handle your structures. It's still there as a fallback.
You can make a form that can absolutely handle what you asking using just normal HTML + Javascript to interact. It can span multiple content structures on the same form.
So, yes, you could have a type field in the primary structure, and then that type can pull from a 'garden' structure OR a 'kitchen' structure. It can give you that second level of abstraction.

Let's try a second way - a SQL vision; now you can have different tables (Primary, Garden, Kitchen) and you can build a 'view' that merges them for interaction.
Here's code that allows a user to add a comment to a page (not being logged in) to report a typo or something like that. It even allows them to upload a file along side of it (like an image or a word doc) to accompany the comment. It uses some tricks ($VTLSERVLET_URI) to get the page url, and I set the page identifier in javascript on each page (ie. document.identifier='$dotPageContent.inode').
You'd need the other bits, but this is a working example.

function addcomment(){   
   
    var formData = new FormData();
 request = new XMLHttpRequest();
request.onreadystatechange = function() {
 
  if (request.readyState == 4){
        if (request.status === 200) {
          console.log("Create Eiffel Connect:");   
          console.log(request.responseText);
            location.href="${VTLSERVLET_URI}?dotcache=refresh";
           
        } else { 
           console.log("Error", request.statusText); 
        } 
 
}
   
 
};

request.open("POST", "/api/content/publish/1", true);  



var comment=document.getElementById('Comment').value;

var d=new Date();
var mon=d.getMonth()+1;
var day=d.getDay()-1;
var atime=d.getFullYear()+"-"+mon+"-"+day+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
console.log(atime);
//User, PageUrl,Identifier, Highlight, Comment, Reported, ResolvedBy, Resolved
 var dataObj={
          'stName':'ParisContentComment',
          'identifier1' : document.identifier,
          'pageurl' : '$VTLSERVLET_URI',
          'user' : '$reviewuser',
          'useremail' : '$reviewemail',
          'userdepartment' : '$reviewdept',
          'userjob' : '$reviewjob',
          'highlight' : document.highlit,
          'comment' : comment,
          'reported': atime,
          'contentHost':'SYSTEM_HOST'};    
   
 formData.append('json',JSON.stringify(dataObj));   
 
var theimager=document.getElementById('tpic');

var file=theimager.files[0];

if (file)
formData.append("document", file);
 

 request.send(formData);  
  
         

}









Mark

On Thu, Aug 10, 2017 at 8:14 AM, Xander Steinmann <[hidden email]> wrote:
Hi Arjen,

I've copy-pasted some code from a macro we used to hide fields based on certain settings. I think this is the main code:

<script>
  dojo.require("dojo.NodeList-traverse");
    document.getElementById('$!{field}_tag').parentNode.style.display = 'none';
</script>

Here "field" is the field id you want to hide. You can use velocity/javascript to read other fields to determine what kind of "product" you are working with and which fields you need to hide.
Note that this is "hiding for convenience". You would need a Hook to prevent users from altering fields that they should not be able to alter.

Kind regards,

Xander

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/8d86c475-dd84-43d5-ba22-ddc93142cc9f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/CAFeiKqMna4%2Byzn_0RCKJw%3DZRE20-tg%2BrzzZXMknLtgVYV2%3DOMg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: 'subclassing' content types

Xander
Mark has a point: you can do anything you want, but the more you want the more work you will need to do. If you want to stick to the basic dotCMS edit content form then hiding with javascript is an easy way to accomplish what you want. And yes, in a Custom field with a radio/pulldown or something would work fine.

Kind regards,

Xander






--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/9123a237-1474-41b0-990b-eaafc5d27bea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: 'subclassing' content types

Mark Pitely
Hah, yes. You have to do your own verification, etc.
So, choose your poison-  either writing javascript within dotCMS's dojo implementation with some Velocity and some tricky custom fields to *slightly* extend the system OR write more generic javascript to  control your custom experience. I've done them both - it really depends on the process you want. For a simple lookup to do a dropdown that originates in a separate structure, they work great.
So, do you need a piece of glue or do you need an app?

I'd also guess that 'custom fields' as they stand are more likely to be deprecated than the API. They are flakier to handle as you have to do them within the backend and harder to debug. But quicker, with no reinvention of the wheel.
You could also (shudder) use java and webhooks... where's Chris to suggest it?


Mark

On Thu, Aug 10, 2017 at 11:12 AM, Xander Steinmann <[hidden email]> wrote:
Mark has a point: you can do anything you want, but the more you want the more work you will need to do. If you want to stick to the basic dotCMS edit content form then hiding with javascript is an easy way to accomplish what you want. And yes, in a Custom field with a radio/pulldown or something would work fine.

Kind regards,

Xander






--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/9123a237-1474-41b0-990b-eaafc5d27bea%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/CAFeiKqM3fdEDHiTo_Gv72XYTJNo%3DLfgLPndHnQg1uY%3DQ6QCe-w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: 'subclassing' content types

Arjen
Hi Mark, yes I do agree with you fully.
We're actually working on a complete bespoke portal which will include these features, but in the mean time we'll have to use the existing interface so if a quick javascript tweak will do it that perfect for now.

Thanks for the example code though, we'll definitely use that for the portal.

Arjen

On Thursday, August 10, 2017 at 4:36:41 PM UTC+1, Mark Pitely wrote:
Hah, yes. You have to do your own verification, etc.
So, choose your poison-  either writing javascript within dotCMS's dojo implementation with some Velocity and some tricky custom fields to *slightly* extend the system OR write more generic javascript to  control your custom experience. I've done them both - it really depends on the process you want. For a simple lookup to do a dropdown that originates in a separate structure, they work great.
So, do you need a piece of glue or do you need an app?

I'd also guess that 'custom fields' as they stand are more likely to be deprecated than the API. They are flakier to handle as you have to do them within the backend and harder to debug. But quicker, with no reinvention of the wheel.
You could also (shudder) use java and webhooks... where's Chris to suggest it?


Mark

On Thu, Aug 10, 2017 at 11:12 AM, Xander Steinmann <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="DhapXcleBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">xan...@...> wrote:
Mark has a point: you can do anything you want, but the more you want the more work you will need to do. If you want to stick to the basic dotCMS edit content form then hiding with javascript is an easy way to accomplish what you want. And yes, in a Custom field with a radio/pulldown or something would work fine.

Kind regards,

Xander






--
<a href="http://dotcms.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdotcms.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGFT4ej1MQxQ2vu3iAUqYQgS59efw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdotcms.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGFT4ej1MQxQ2vu3iAUqYQgS59efw&#39;;return true;">http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="DhapXcleBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">dotcms+un...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="DhapXcleBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">dot...@....
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/dotcms/9123a237-1474-41b0-990b-eaafc5d27bea%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/dotcms/9123a237-1474-41b0-990b-eaafc5d27bea%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/dotcms/9123a237-1474-41b0-990b-eaafc5d27bea%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/dotcms/9123a237-1474-41b0-990b-eaafc5d27bea%40googlegroups.com.

For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/8a6a9829-71e2-4e43-a1d8-8922ae04fe36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.