Skip to content

Instantly share code, notes, and snippets.

@cmcdevitt
Created October 7, 2022 14:11
Show Gist options
  • Select an option

  • Save cmcdevitt/982d42e411346ef3ed06255359137898 to your computer and use it in GitHub Desktop.

Select an option

Save cmcdevitt/982d42e411346ef3ed06255359137898 to your computer and use it in GitHub Desktop.
Portal Widget Client Script Example
/*
Widget Client Script
I am not a SN Portal person so take this with a grain of salt!
*/
function($scope) {
/* widget controller */
var c = this;
c.config = {
outputType: "encoded_query",
closeFilter: false,
encodedQuery: massageEncodedQuery(c.data.initialQuery),
manageFiltersLink: "?id=lf&table=sys_filter"
};
//Event Listner - generic events(?)
$scope.$on("field.change", function(evt,parms){
var field = parms.field.name;
var tableName = parms.newValue;
if(field != 'some_event_name'){
/*
Important.....
You need to make this "generic" listner "specific" otherwise it work on all EVENTS
This example exits the function if the event is not 'some_event_name'
*/
return;
}
//do work
})
//Event Listner Specific
$scope.$on("snfilter:update_query", function(e, query){
//$scope.page.g_form.setValue('encoded_query',massageEncodedQuery(query)); //Not neccessary
$scope.page.g_form.setValue('encoded_query',query);
});
function massageEncodedQuery(encodedQuery) {
return (encodedQuery) ? encodedQuery.replace(/CONTAINS/g, "LIKE").replace(/DOES NOT CONTAIN/g, "NOT LIKE") : encodedQuery;
}
}
/*
How to find an Event
You need to search the Widgets "dependencies" aka JavaScript
sp_widget - Table
Example: SN Desktop widget -> using a Widget Dependency -> Angular Directive (SN Filter)
Look at JS dependencies, look for: $brodcast (<- events)
Then test the events to find the one you need
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment