@@ -4,81 +4,93 @@ import { Utility } from './levelup.common.utility';
4
4
import { IResultRow } from '../interfaces/types' ;
5
5
6
6
export class Grid {
7
- constructor ( private utility : Utility ) { }
7
+ constructor ( private utility : Utility ) { }
8
8
9
- quickFindFields ( ) {
10
- let currentView = this . utility . formDocument . querySelector ( 'span.ms-crm-View-Name' ) ,
11
- resultsArray : IResultRow [ ] = [ { cells : [ 'Quick Find Attribute' ] } ] ,
12
- etc = this . utility . Xrm . Page . context . getQueryStringParameters ( ) . etc ,
13
- // @ts -ignore
14
- entityName = this . utility . Xrm . Internal . getEntityName ( parseInt ( etc ) ) ;
15
- // @ts -ignore
16
- if ( ! entityName && this . utility . Xrm . Utility . getPageContext ) {
17
- // @ts -ignore
18
- let view = this . utility . Xrm . Utility . getPageContext ( ) . input ;
19
- entityName = view . entityName ;
20
- }
21
- if ( entityName ) {
22
- let attributes = 'FetchXml' ,
23
- entitySetName = this . utility . is2016OrGreater ? 'savedqueries' : 'SavedQuerySet' ;
24
- if ( this . utility . is2016OrGreater ) {
25
- attributes = attributes . toLowerCase ( ) ;
26
- }
27
- let filter = this . utility . is2016OrGreater
28
- ? `isquickfindquery eq true and querytype eq 4 and returnedtypecode eq '${ entityName } '`
29
- : `IsQuickFindQuery eq true and QueryType eq 4 and ReturnedTypeCode eq '${ entityName } '` ;
30
- this . utility . fetch ( entitySetName , attributes , filter ) . then ( ( view ) => {
31
- let quickFindFields = [ ] ;
32
- if ( this . utility . is2016OrGreater ) {
33
- quickFindFields = Array . from (
34
- new DOMParser ( ) . parseFromString ( view [ 0 ] . fetchxml , 'text/html' ) . querySelectorAll ( 'condition' )
35
- ) . map ( ( x ) => x . getAttribute ( 'attribute' ) ) ;
36
- } else {
37
- quickFindFields = Array . from (
38
- new DOMParser ( ) . parseFromString ( view [ 0 ] . FetchXml , 'text/html' ) . querySelectorAll ( 'condition' )
39
- ) . map ( ( x ) => x . getAttribute ( 'attribute' ) ) ;
40
- }
41
- quickFindFields . forEach ( ( x ) => resultsArray . push ( { cells : [ x ] } ) ) ;
42
- this . utility . messageExtension ( resultsArray , 'quickFindFields' ) ;
43
- } ) ;
44
- } else {
45
- alert ( 'The current page is not a grid' ) ;
46
- }
47
- }
9
+ quickFindFields ( ) {
10
+ let currentView = this . utility . formDocument . querySelector ( 'span.ms-crm-View-Name' ) ,
11
+ resultsArray : IResultRow [ ] = [ { cells : [ 'Quick Find Attribute' ] } ] ,
12
+ etc = this . utility . Xrm . Page . context . getQueryStringParameters ( ) . etc ,
13
+ // @ts -ignore
14
+ entityName = this . utility . Xrm . Internal . getEntityName ( parseInt ( etc ) ) ;
15
+ // @ts -ignore
16
+ if ( ! entityName && this . utility . Xrm . Utility . getPageContext ) {
17
+ // @ts -ignore
18
+ let view = this . utility . Xrm . Utility . getPageContext ( ) . input ;
19
+ entityName = view . entityName ;
20
+ }
21
+ if ( entityName ) {
22
+ let attributes = 'FetchXml' ,
23
+ entitySetName = this . utility . is2016OrGreater ? 'savedqueries' : 'SavedQuerySet' ;
24
+ if ( this . utility . is2016OrGreater ) {
25
+ attributes = attributes . toLowerCase ( ) ;
26
+ }
27
+ let filter = this . utility . is2016OrGreater
28
+ ? `isquickfindquery eq true and querytype eq 4 and returnedtypecode eq '${ entityName } '`
29
+ : `IsQuickFindQuery eq true and QueryType eq 4 and ReturnedTypeCode eq '${ entityName } '` ;
30
+ this . utility . fetch ( entitySetName , attributes , filter ) . then ( ( view ) => {
31
+ let quickFindFields = [ ] ;
32
+ if ( this . utility . is2016OrGreater ) {
33
+ quickFindFields = Array . from (
34
+ new DOMParser ( ) . parseFromString ( view [ 0 ] . fetchxml , 'text/html' ) . querySelectorAll ( 'condition' )
35
+ ) . map ( ( x ) => x . getAttribute ( 'attribute' ) ) ;
36
+ } else {
37
+ quickFindFields = Array . from (
38
+ new DOMParser ( ) . parseFromString ( view [ 0 ] . FetchXml , 'text/html' ) . querySelectorAll ( 'condition' )
39
+ ) . map ( ( x ) => x . getAttribute ( 'attribute' ) ) ;
40
+ }
41
+ quickFindFields . forEach ( ( x ) => resultsArray . push ( { cells : [ x ] } ) ) ;
42
+ this . utility . messageExtension ( resultsArray , 'quickFindFields' ) ;
43
+ } ) ;
44
+ } else {
45
+ alert ( 'The current page is not a grid' ) ;
46
+ }
47
+ }
48
48
49
- openGrid ( ) {
50
- let currentView = this . utility . formDocument . querySelector ( 'span.ms-crm-View-Name' ) ,
51
- etc = this . utility . Xrm . Page . context . getQueryStringParameters ( ) . etc ,
52
- etn ,
53
- viewId ,
54
- viewType ;
55
- // @ts -ignore
56
- if ( ( ! currentView || ! etc ) && this . utility . Xrm . Utility . getPageContext ) {
57
- // @ts -ignore
58
- let view = this . utility . Xrm . Utility . getPageContext ( ) . input ;
59
- etn = view . entityName ;
60
- viewId = view . viewId ;
61
- viewType = view . viewType ;
62
- }
63
- if ( etn ) {
64
- if ( ! viewId ) {
65
- window . open ( `${ this . utility . clientUrlForParams } etn=${ etn } &newWindow=true&pagetype=entitylist` , '_blank' ) ;
66
- } else {
67
- let viewTypeCode ;
68
- if ( viewType === 'savedquery' ) viewTypeCode = 1039 ;
69
- if ( viewType === 'userquery' ) viewTypeCode = 4230 ;
70
- window . open (
71
- `${ this . utility . clientUrlForParams } pagetype=entitylist&etn=${ etn } &viewid=${ viewId } &viewType=${ viewTypeCode } ` ,
72
- '_blank'
73
- ) ;
74
- }
75
- } else if ( currentView && etc ) {
76
- let viewType = currentView . getAttribute ( 'currentviewtype' ) ,
77
- viewId = currentView . getAttribute ( 'currentview' ) ,
78
- viewUrl = `${ this . utility . clientUrlForParams } etc=${ etc } &viewtype=${ viewType } &viewid=${ viewId } &newWindow=true&pagetype=entitylist` ;
79
- window . open ( viewUrl , '_blank' ) ;
80
- } else {
81
- alert ( 'The current page is not a grid' ) ;
82
- }
83
- }
49
+ openGrid ( ) {
50
+ let currentView = this . utility . formDocument . querySelector ( 'span.ms-crm-View-Name' ) ,
51
+ etc = this . utility . Xrm . Page . context . getQueryStringParameters ( ) . etc ,
52
+ etn ,
53
+ viewId ,
54
+ viewType ;
55
+ // @ts -ignore
56
+ if ( ( ! currentView || ! etc ) && this . utility . Xrm . Utility . getPageContext ) {
57
+ // @ts -ignore
58
+ let view = this . utility . Xrm . Utility . getPageContext ( ) . input ;
59
+ etn = view . entityName ;
60
+ viewId = view . viewId ;
61
+ viewType = view . viewType ;
62
+ }
63
+ if ( etn ) {
64
+ if ( ! viewId ) {
65
+ window . open ( `${ this . utility . clientUrlForParams } etn=${ etn } &newWindow=true&pagetype=entitylist` , '_blank' ) ;
66
+ } else {
67
+ let viewTypeCode ;
68
+ if ( viewType === 'savedquery' ) viewTypeCode = 1039 ;
69
+ if ( viewType === 'userquery' ) viewTypeCode = 4230 ;
70
+ window . open (
71
+ `${ this . utility . clientUrlForParams } pagetype=entitylist&etn=${ etn } &viewid=${ viewId } &viewType=${ viewTypeCode } ` ,
72
+ '_blank'
73
+ ) ;
74
+ }
75
+ } else if ( currentView && etc ) {
76
+ let viewType = currentView . getAttribute ( 'currentviewtype' ) ,
77
+ viewId = currentView . getAttribute ( 'currentview' ) ,
78
+ viewUrl = `${ this . utility . clientUrlForParams } etc=${ etc } &viewtype=${ viewType } &viewid=${ viewId } &newWindow=true&pagetype=entitylist` ;
79
+ window . open ( viewUrl , '_blank' ) ;
80
+ } else {
81
+ alert ( 'The current page is not a grid' ) ;
82
+ }
83
+ }
84
+
85
+ blurView ( ) {
86
+ setFilter ( this . utility . formDocument , 'blur(5px)' ) ;
87
+ }
88
+
89
+ resetViewBlur ( ) {
90
+ setFilter ( this . utility . formDocument , '' ) ;
91
+ }
92
+ }
93
+
94
+ function setFilter ( formDocument : Document , filter : string ) {
95
+ formDocument . querySelectorAll ( '.wj-row[aria-label="Data"]' ) . forEach ( ( e : HTMLElement ) => ( e . style . filter = filter ) ) ;
84
96
}
0 commit comments