Created
October 7, 2022 14:11
-
-
Save cmcdevitt/982d42e411346ef3ed06255359137898 to your computer and use it in GitHub Desktop.
Portal Widget Client Script Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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