Alfresco datalist send email on very new item creation - javascript

I have applied rule on datalist folder like on each item creation, it should drop an email to respective person.
Below is the script for the same:
function main()
{
var site = siteService.getSite("hardik-test");
var dataListsContainer = site.getContainer("datalists");
var dataLists = dataListsContainer.getChildren();
var fullName, manager,joiningDate;
for(var x=0;x<dataLists.length;x++)
{
var dataList = dataLists[x];
var props = dataList.getProperties();
var title = props["cm:title"];
if(title.equals("Employee"))
{
var dataListItems = dataList.getChildren();
for (var y = 0; y < dataListItems.length; y++)
{
var dataListItem = dataListItems[dataListItems.length-1];
var dataListItemProps = dataListItem.getProperties();
fullName = dataListItemProps["emp:fullName"];
manager = dataListItemProps["emp:manager"];
joiningDate = dataListItemProps["emp:joiningDate"];
}
}
}
// create mail action
var mail = actions.create("mail");
mail.parameters.to = "xyz#xyz.com"; //manager email id should be there
mail.parameters.subject = "Task assigned to you.";
mail.parameters.from = "xyz#xyz.com";
//mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Notify Email Templates/notify_user_email.html.ftl");
mail.parameters.text = "Hi "+manager +"," + "\n A new employee " +fullName +" will be joining our team on "+ joiningDate + "." +
"\n For details, Please click here. \n Regards, \n Administrator" ;
mail.execute(document);
}
script is running every time when we create new item but in the email it's not fetching the latest data we entered.
If we want to use email template, then how can we pass parameter(custom values) to email template?
Want to create link that will redirect to datalist.

This is one of the many times when the Alfresco source can be instructive. If you take a look at the MailActionExecuter class you'll see that it has several parameters defined:
public static final String NAME = "mail";
public static final String PARAM_LOCALE = "locale";
public static final String PARAM_TO = "to";
public static final String PARAM_CC = "cc";
public static final String PARAM_BCC = "bcc";
public static final String PARAM_TO_MANY = "to_many";
public static final String PARAM_SUBJECT = "subject";
public static final String PARAM_SUBJECT_PARAMS = "subjectParams";
public static final String PARAM_TEXT = "text";
public static final String PARAM_HTML = "html";
public static final String PARAM_FROM = "from";
public static final String PARAM_FROM_PERSONAL_NAME = "fromPersonalName";
public static final String PARAM_TEMPLATE = "template";
public static final String PARAM_TEMPLATE_MODEL = "template_model";
public static final String PARAM_IGNORE_SEND_FAILURE = "ignore_send_failure";
public static final String PARAM_SEND_AFTER_COMMIT = "send_after_commit";
One of those is PARAM_TEMPLATE_MODEL which you would set by using "template_model". The "model" in that parameter is what should be catching your eye. It means you can pass in a set of keys and values by using that parameter.
Later, in the source for that class we see where the parameter is read and then used to build the full model that is then passed in to the Freemarker template:
Map<String, Object> suppliedModel = null;
if(ruleAction.getParameterValue(PARAM_TEMPLATE_MODEL) != null)
{
Object m = ruleAction.getParameterValue(PARAM_TEMPLATE_MODEL);
if(m instanceof Map)
{
suppliedModel = (Map<String, Object>)m;
}
else
{
logger.warn("Skipping unsupported email template model parameters of type " + m.getClass().getName() + " : " + m.toString());
}
}
// build the email template model
Map<String, Object> model = createEmailTemplateModel(actionedUponNodeRef, suppliedModel, fromPerson, toRecipients);
So, if you comment in the reference to the template and you pass in an additional parameter to the action, assuming your template makes use of the items you add to the model, you should see those in the resulting email.
Your code would look something like:
var templateModel = {};
templateModel["fullName"] = fullName;
templateModel["manager"] = manager;
templateModel["joiningDate"] = joiningDate;
mail.parameters.template_model = templateModel;

Related

how to get model values in javascript

testModel
public class testModel
{
public int ID{get; set;}
public string name{get; set;}
}
cshtml code
#model IEnumerable<testModel>
var lstModel = Model.ToList();
<div id="mainOfferDiv">
#for(int i = 0; i<lstModel.Count(); i++)
{
}
</div
In js file i want to get list of testModel data which is there in cshtml file, I tried with below
js file
var listModel = document.getElementById("mainOfferDiv");
Suppose lstModel contains list of 10data i want to get same in js file
Thank you in advance
You could take your entire server-side model and turn it into a Javascript object by doing the following:
var model = #Html.Raw(Json.Encode(Model));
In your case if you just want the FloorPlanSettings object, simply pass the Encode method that property:
var floorplanSettings = #Html.Raw(Json.Encode(Model.FloorPlanSettings));
another way is
Classs property ---
Name = "Raj",
IsAuthenticated = true,
LoginDateTime = DateTime.Now,
Age = 26,
UserIconHTML = "<i class='fa fa-users'></i>"
---------------------------------
js in cshtml
var Name = #Model.Name;
var Age = #Model.Age;
var LoginTime = #Model.LoginDateTime;
var IsAuthenticated = #Model.IsAuthenticated;
var IconHtml = #Model.UserIconHTML;

How can I convert javascript var obj = {}; to C#?

I have the following javascript code:
var key = "Mykey" + NextNumber.toString();
var value = {"Name":"Tony","Width":"150","Height":"320"};
var valuejson = JSON.stringify(value);
var obj = {};
obj[key] = valuejson
I know how to create valuejson in C#, but I don't know how to create something similar like var obj = {}; in C#. How can I do that in C#?
key and valuejson in C#:
public class MyValue
{
public string Name { get; set; }
public string Width { get; set; }
public string Height { get; set; }
}
MyValue value = new MyValue();
value.Name = "Tony";
value.Width = "150";
value.Height = "320";
string jsonValue = JsonConvert.SerializeObject(value);
string key = "Mykey" + NextNumber.toString();
You could try to use a dynamic object which works similar to {} in javascript... But... You have to be CAREFUL, example:
public class test
{
public class MyValue
{
public string Name { get; set; }
public string Width { get; set; }
public string Height { get; set; }
}
public void testing()
{
MyValue value = new MyValue();
value.Name = "Tony";
value.Width = "150";
value.Height = "320";
dynamic jsonValue = new { keyA = value };
string height = jsonValue.keyA.Height;
}
}
EDI:
Actually, I read a bit more carefully your need, and a dictionary can also suit your needs:
public class test
{
public class MyValue
{
public string Name { get; set; }
public string Width { get; set; }
public string Height { get; set; }
}
Dictionary<string, MyValue> dic = new Dictionary<string, MyValue>();
public void testing()
{
string key = "Mykey" + NextNumber.toString();
MyValue value = new MyValue();
value.Name = "Tony";
value.Width = "150";
value.Height = "320";
dic.Add(key, value);
}
}
Since you where asking for the equivalent of a var x = {} I suggested the dynamic but I see you want to create a key and associate that value to that key.
If you're looking for an object whose members can be dynamically added and removed at run time (like in Javascript) then the ExpandoObject class should fit your needs.
dynamic employee = new ExpandoObject();
employee.Name = "John Smith";
employee.Age = 33;
foreach (var property in (IDictionary<String, Object>)employee)
{
Console.WriteLine(property.Key + ": " + property.Value);
}
// This code example produces the following output:
// Name: John Smith
// Age: 33
You are asking for dynamic ExpandoObject.
Example:
dynamic obj = new ExpandoObject();
obj.banana = "CIAO";
obj.bidshmqwq = 11245;
obj.BRUFCJMWH = null;
In substance, this Type can let you declare object's properties dynamically.
To convert from a json string to a C# object, you can use the DeserializeObject method and pass in an instance of the c# object that you want to convert this json to. The JsonConvert library is part of the Newtonsoft.Json library.
var converted = JsonConvert.DeserializeObject<myCSharpViewModel>(json);

Blazor Dynamic Root Variables

I'm looking to build a website that works in the same manner that I have put together in this video, that isn't based on JS ( like it is in this video ), that can utilize C# in order to interop with JS and get windowWidth and windowHeight, and then dynamically change all of the CSS variables so that all of the content, images, and font size/shading/border/shadows, etc... will all scale as the page is zoomed in or out.
The end result is, to make a size that works for a single resolution and then scales all the way down to the 320w to 3200w resolutions out there. That means, one website, one template, no messing around with a thousand different iterations of the way the site should look.
I spent about a week trying to develop some C# code that could in fact change and set the variables, however, I'm not a seasoned C# veteran, I prefer to write everything in PS.
I understand the limitations of Blazor, and how it 'diffs' the state changes upon rendering, but if BlazorStyled can modify the CSS, then I see no reason why it would be impossible for the window width/height to directly influence the variables that the site runs off of.
I did study drafting and design, I left the field before I was able to study programming and C#/.Net in order to further what I could do with HTML and CSS more than a decade ago... same goes for the MCSE/MCSA curriculum that I also gave up on...
...but I've spent the last year 'catching up' on all of it.
https://youtu.be/Z99zsCwYhWk <- this is what I am attempting to perform in Blazor. This is utilizing javascript and document.queryselector, document.setproperty... I am not certain that it is possible to do these things either with or without JSInterop, and yes... i know how to change the css types with media queries... I'm attempting to build a forloop that captures every possible resolution out there and scales for every pixel within that loop.
But also, considers the fact that the layouts can have multiple formats that correspond to these dynamic variables. So as I've showcased in the video, below 720w the navigation bar will shift to the top, which can be done with native CSS media queries, but what can't be done is changing the DOM elements without screwing up the way Blazor works. I've tried. Even spent a week trying to write the C# code that would use JSInterop and the custom classes and dimensions and change the properties accordingly...
Upon compile... it said "I have failed." It said it a few times... So I was like damn. Spent a whole week trying to do something super cool... and this program looked at me and said "Bro. I don't like this input..."
But what can I do?
Given the nature of ASP.Net/Blazor, I won't post the code because there's a lot of content. I can give you a run down of what I have tried so far...
I found Chris Sainty's old project on github called "browserResize". But I think this breaks the rules of Blazor component [quantization and hyperspeed time space continuum effect displacement of the thermodynamic laws of physics ... everything in these brackets is comic relief]
I already had a fully blown javascript file that had all of the operations I needed inside, but, how do you get Blazor to work when the official Microsoft Blazor FAQ says
"Don't use JS for all that... cause that's lame." -Microsoft
After I read that quote that Microsoft put into the official FAQ... I thought... well, it's time to give it a grade A try anyway ... so I then implemented some classes that create objects in a similar manner to
```
# Heroes in a half 'Shell #
[PSCustomObject]#{
width = "window.innerWidth"
height = "window.innerHeight"
}
```
...only it is a lot more than that.
I made some JSInterop calls based on Nick Chapas' videos about it, and I'm pretty sure that I wrote all that correctly...? Not certain.
Then I made a service that could, upon resizing the window, set all of the corresponding CSS elements, and theoretically change the CSS styling of everything on the page given the conditions I showcase in the video link above.
I'm sure I may have overexplained what I'm attempting to do...? But, I'm burning a lot of time theorizing, not enough 'actually getting work done'. And, there comes a point in time where you may in fact be learning a great deal on new ways to get nowhere... but the case could also be made that 'there are better ways to make use of your time...'
Plz help. Thx bros.
(Edit: At the request of Iraklis, here are the two bits of code I made)
.\ - represents the base repo folder.
.\Data\Controller.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.JSInterop;
namespace ShellBlaze.Data
{
public class Controller
{
public static readonly IJSRuntime JSR;
public class Window
{
public async Task<int> Height()
{
return await JSR.InvokeAsync<int>( "getHeight" );
}
public async Task<int> Width()
{
return await JSR.InvokeAsync<int>( "getWidth" );
}
public async Task<object> QuerySelect( string Tag )
{
return await JSR.InvokeAsync<object>( "querySelect" , Tag );
}
public async Task SetProperty( object ID , string Property , string Value )
{
await JSR.InvokeVoidAsync( "setProperty" , ID , Property , Value );
}
}
public class Stage
{
Controller.Window Windex = new Controller.Window();
Model.Window Win = new Model.Window();
Model.Layout Lay = new Model.Layout();
public async Task<Model.Layout> Action()
{
Win.Height = await Windex.Height();
Win.Width = await Windex.Width();
Win.Side = Win.Width * 0.15f;
Win.Main = Win.Width * 0.85f;
Win.Pixel = Win.Width / 1920;
var Root = Windex.QuerySelect( ":root" );
int[] Ct = { 0, 1, 2, 3 };
string[] Element = { "root" , "side" , "main" , "pixel" };
double[] Unit = { Win.Width , Win.Side , Win.Main , Win.Pixel };
string[] Name = { "#top", "#side", "body" , "#main" };
string[] Property = { "display", "display", "flex-direction", "--content" };
string[] Value = new string[3];
string[] Value1 = { "flex", "none", "column", Win.Width + "px" };
string[] Value2 = { "none", "flex", "row", Win.Main + "px" };
if (Win.Width < 720)
{
Value = Value1;
}
else
{
Value = Value2;
}
foreach (int i in Ct)
{
await Windex.SetProperty( Root, "--" + Element[i], Unit[i] + "px" );
await Windex.SetProperty( Windex.QuerySelect( Name[i] ), Property[i], Value[i] );
}
if (Win.Width > 720)
{
Lay.Type = "top";
Lay.Logo = "toplogo";
Lay.ID = "ti";
Lay.Class0 = "t0";
Lay.Class1 = "t1";
Lay.Class2 = "t2";
Lay.Class3 = "t3";
Lay.Class4 = "t4";
Lay.Class5 = "t5";
Lay.Class6 = "t6";
Lay.String0 = "Home";
Lay.String1 = "App Development";
Lay.String2 = "Network Security";
Lay.String3 = "Enterprise";
Lay.String4 = "OS Management";
Lay.String5 = "Hardware";
Lay.String6 = "Data Management";
return Lay;
}
else
{
Lay.Type = "side";
Lay.Logo = "sidelogo";
Lay.ID = "si";
Lay.Class0 = "t0";
Lay.Class1 = "t1";
Lay.Class2 = "t2";
Lay.Class3 = "t3";
Lay.Class4 = "t4";
Lay.Class5 = "t5";
Lay.Class6 = "t6";
Lay.String0 = "Home";
Lay.String1 = "App<br/>Development";
Lay.String2 = "Network<br/>Security";
Lay.String3 = "Enterprise";
Lay.String4 = "OS<br/>Management";
Lay.String5 = "Hardware";
Lay.String6 = "Data<br/>Management";
return Lay;
}
}
}
public class State
{
public static event Func<Task> Trip;
[JSInvokable]
public static async Task Set()
{
Controller.Stage Stage = new Controller.Stage();
await Stage.Action();
await JSR.InvokeAsync<object>( "setEvent" );
await Trip?.Invoke();
}
}
}
}
.\Data\Model.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ShellBlaze.Data
{
public class Model
{
public class Layout
{
public string Type { get; set; }
public string Logo { get; set; }
public string ID { get; set; }
public string Class0 { get; set; }
public string Class1 { get; set; }
public string Class2 { get; set; }
public string Class3 { get; set; }
public string Class4 { get; set; }
public string Class5 { get; set; }
public string Class6 { get; set; }
public string String0 { get; set; }
public string String1 { get; set; }
public string String2 { get; set; }
public string String3 { get; set; }
public string String4 { get; set; }
public string String5 { get; set; }
public string String6 { get; set; }
public Layout()
{
Type = null;
Logo = null;
ID = null;
Class0 = null;
Class1 = null;
Class2 = null;
Class3 = null;
Class4 = null;
Class5 = null;
Class6 = null;
String0 = null;
String1 = null;
String2 = null;
String3 = null;
String4 = null;
String5 = null;
String6 = null;
}
public Layout(
string _Type,
string _Logo,
string _ID,
string _Class0,
string _Class1,
string _Class2,
string _Class3,
string _Class4,
string _Class5,
string _Class6,
string _String0,
string _String1,
string _String2,
string _String3,
string _String4,
string _String5,
string _String6
)
{
Type = _Type;
Logo = _Logo;
ID = _ID;
Class0 = _Class0;
Class1 = _Class1;
Class2 = _Class2;
Class3 = _Class3;
Class4 = _Class4;
Class5 = _Class5;
Class6 = _Class6;
String0 = _String0;
String1 = _String1;
String2 = _String2;
String3 = _String3;
String4 = _String4;
String5 = _String5;
String6 = _String6;
}
}
public class Sheet
{
public object ID { get; set; }
public string Tag { get; set; }
public string Property { get; set; }
public string Value { get; set; }
public Sheet()
{
ID = null;
Tag = null;
Property = null;
Value = null;
}
public Sheet( object _ID , string _Tag , string _Property , string _Value )
{
ID = _ID;
Tag = _Tag;
Property = _Property;
Value = _Value;
}
}
public class Window
{
public int Height { get; set; }
public int Width { get; set; }
public double Side { get; set; }
public double Main { get; set; }
public double Pixel { get; set; }
public Window()
{
Height = 0;
Width = 0;
Side = 0.00f;
Main = 0.00f;
Pixel = 0.00f;
}
public Window( int _Height , int _Width , double _Side , double _Main , double _Pixel )
{
Height = _Height;
Width = _Width;
Side = _Side;
Main = _Main;
Pixel = _Pixel;
}
}
}
}
.\Scripts\script.js
function querySelect(Tag)
{
return document.querySelector( '"' + Tag + '"' );
}
function setProperty(ID, Property, Value )
{
ID.style.setProperty( "'" + Property + "'" , "'" + Value + Unit + "'" );
}
function getHeight()
{
return window.innerHeight;
}
function getWidth()
{
return window.innerWidth;
}
function setEvent()
{
DotNet.invokeMethodAsync( "Resize" , "Set" ).then(data => data);
window.addEventListener( "resize" , setEvent() );
}

return Tuple to js in view

Tried using c# 7 Tuples like
public (string, bool) ProcessForm([FromBody]Dictionary<string,string> contactFormRequest)
But I get the error "CS1031: Type expected". I guess this isn't supported yet.
Then I tried
public Tuple<string, bool> ProcessForm([FromBody]Dictionary<string,string> contactFormRequest)
{
var message = "test";
var result = true;
var tuple = new Tuple<string, bool>(message, result);
return tuple;
}
This gives no error, but then I cannot pick it up in the view file
function handleResult(data) {
$("#custommessages").html(data.Item1);
}
$2sxc(#Dnn.Module.ModuleID).webApi.post("Form/ProcessForm", {}, newItem, true).then(handleResult);
This outputs nothing.
If I return a simple string from the controller, "data" picks it fine.
How do you pick up the values from a Tuple return?
Why not create a POCO class for serialization:
public class SomeResult
{
public string Message{get;set;}
public bool Result{get;set;}
}
then
public SomeResult ProcessForm([FromBody]Dictionary<string,string> contactFormRequest)
{
var message = "test";
var result = true;
return new SomeResult{Message = message, Result = result};
}
Why not just return a IActionResult?
You can simply write an Anonymous type instead of Tuple!
Named Types may take up some useless spaces (As I thinks that...)
Try This:
public IActionResult ProcessForm([FromBody]Dictionary<string,string> contactFormRequest)
{
var message = "test";
var result = true;
//This will create an anonymous type! (you can see its named as "a'")
var resultData = new { Message = message, Result = result };
return Json(resultData);
}
Wish it may help you.

dropdownlist not showing data properly

i have this dropdown list which get the data from db but does not display the data properly n the view
The codes are as follows:
View:
#Html.DropDownListFor(m=> Model.SystemRAteModel.Role, new SelectList(Model.SystemRAteModel.GetRole.Items),"Value","Text")
Model:
public class SystemRolesModel
{
public static RoleProvider Provider { get; internal set; }
public int ID { get; set; }
public String Role { get; set; }
public Boolean Status { get; set; }
public SelectList GetRole { get; set; }
}
Controller
public ActionResult Index()
{
IApplicationLogic app = new ApplicationLogic(session);
RateManagementModel RTM = new RateManagementModel();
var value = app.GetVatValue();
var freight = app.GetFreightValue();
// var systemrolemodel = new SystemRolesModel();
//var currency = new List<SelectList>();
// currency= app.GetListOfRoles();
//IList<string> ERModel = new List<string>();
//foreach (var _currency in currency)
//{
// var curent = _currency.ToString();
// ERModel.Add(curent);
//}
var sysmodel = new SystemRolesModel();
sysmodel.GetRole = getRoleSelectList();
RTM.SystemRAteModel = sysmodel;
ViewData["ViewVatValue"] = value;
//ViewData["ViewCurrency"] = new SelectList(currency);
//ViewBag.LocationList = freight;
ViewData["ViewFreightValue"] = freight;
return View("Index",RTM);
}
public SelectList getRoleSelectList()
{
IApplicationLogic app = new ApplicationLogic(session);
var roles = app.GetListOfRoles();
SystemRoles sr = new SystemRoles();
sr.Id = -1;
sr.Role = "--select role--";
roles.Add(sr);
IEnumerable<SystemRoles> sortedRoles = roles.OrderBy(d => d.Id);
IList<SystemRoles> _sortedRoles = sortedRoles.ToList();
return new SelectList(_sortedRoles, "Id", "Role");
}
i have tried everything on the net but cant get a hand on it. Please any help will do.OutPut of my System At the moment
You don't need to create a new SelectList again in View, as you are already creating that in controller side and passing it via Model, you should be able to directly use it in View like:
#Html.DropDownListFor(m=> Model.SystemRAteModel.Role,Model.SystemRAteModel.GetRole)
This should populate the dropdown with the values, but it would display same values for all the items for now, as your code is setting hard-coded same values for all properties here:
SystemRoles sr = new SystemRoles();
sr.Id = -1;
sr.Role = "--select role--";
roles.Add(sr);
You would need to change it to have proper values.
Another easy way can be to use the constructor of SelectList this way:
public SelectList getRoleSelectList()
{
IApplicationLogic app = new ApplicationLogic(session);
var roles = app.GetListOfRoles().OrderBy(x=> x.RoleID);
return new SelectList(roles.ToList(), "RoleID", "Role");
}
you will just need to replace RoldID and Role property name with the proerty names you have in the DTO.
Hope it helps.
See this example:
#Html.DropDownList("Name", Model.Select(modelItem => new SelectListItem
{
Text = modelItem.Name,
Value = modelItem.Id.ToString(),
Selected = modelItem.Id == "12314124"
}))

Categories

Resources