-
Notifications
You must be signed in to change notification settings - Fork 1
/
orientation_oncataloged.js
173 lines (84 loc) · 4.51 KB
/
orientation_oncataloged.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// Copyright (c) 2021, James Grace
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
//
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var VERSION = "14july2021";
var DISPLAY_NAME = "Orientation";
var IGNORE_CATALOGS = ["Archive","Expired","Mobile Uploads","Current"]; //
var FIELD = "Orientation"; // [ ! ] - Don't forget to create this custom field !
var WIDTH_GREATER_HEIGHT = "Landscape"; //
var HEIGHT_GREATER_WIDTH = "Portait"; //
var WIDTH_EQUAL_HEIGHT = "Square"; //
var SKIP_EXISTING = "Yes"; // "Yes" or "No" //
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getProperties() {
return { triggerPoints: ["onCataloged"] };
}
function onCataloged(catalogId, assetId) {
const catalog = catalogId;
const itemId = assetId;
const asset = portfolio.getAssetById(catalogId, assetId);
if ( IGNORE_CATALOGS.indexOf(String(portfolio.getCatalogName(catalog))) > -1 ) {
portfolio.log('[ ' + DISPLAY_NAME + ' version ' + VERSION + ' ] - \\\\\\\\\\\\\\\\\\\\ END Job \\\\\\\\\\\\\\\\\\\\');
} else {
portfolio.log('[ ' + DISPLAY_NAME + ' version ' + VERSION + ' ] - ////////// START Job //////////');
if ( SKIP_EXISTING.toLowerCase() == "yes" ) {
checkExisting(catalog, asset, itemId);
} else {
getDimensions(catalog, asset, itemId);
} // else
} // else
} // onCataloged
function checkExisting (catalog, asset, itemId) {
if ( portfolio.getFieldDefinitions(catalog, [FIELD], false).length === 1 ) {
portfolio.log('[ checkExisting ] = [ "' + FIELD + '" ] exists !');
if ( [WIDTH_GREATER_HEIGHT,HEIGHT_GREATER_WIDTH,WIDTH_EQUAL_HEIGHT].indexOf(asset.getSingleValueForName(FIELD)) >=0 ) {
portfolio.log('[ checkExisting ] = [ Value for "' + FIELD + '" ] exists !');
} else {
getDimensions(catalog, asset, itemId);
} // else
} else {
portfolio.log('[ ERROR ! ] : Please ensure that the "' + FIELD + '" Custom Field has been created !');
} // else
} // checkExisting
function getDimensions (catalog, asset, itemId) {
let WIDTH = asset.getSingleValueForName("Width");
let HEIGHT = asset.getSingleValueForName("Height");
if ( WIDTH == null || HEIGHT == null ) {
portfolio.log('[ ' + DISPLAY_NAME + ' version ' + VERSION + ' ] : Item ID [ ' + itemId + ' ] - The "Width" and / or "Height" fields are empty !');
} else {
WIDTH = parseInt(WIDTH);
HEIGHT = parseInt(HEIGHT);
var ORIENTATION;
if ( WIDTH > HEIGHT ) {
ORIENTATION = WIDTH_GREATER_HEIGHT;
portfolio.log( '[ WIDTH_GREATER_HEIGHT ] : [ Item ID ] = [ ' + itemId + ' ] ; [ WIDTH ] = [ ' + WIDTH + ' ] ; [ HEIGHT ] = [ ' + HEIGHT + ' ] ; [ ORIENTATION ] = [ ' + ORIENTATION + ' ]');
} else if ( WIDTH < HEIGHT ) {
ORIENTATION = HEIGHT_GREATER_WIDTH;
portfolio.log( '[ HEIGHT_GREATER_WIDTH ] : [ Item ID ] = [ ' + itemId + ' ] ; [ WIDTH ] = [ ' + WIDTH + ' ] ; [ HEIGHT ] = [ ' + HEIGHT + ' ] ; [ ORIENTATION ] = [ ' + ORIENTATION + ' ]');
} else {
ORIENTATION = WIDTH_EQUAL_HEIGHT;
portfolio.log( '[ WIDTH_EQUAL_HEIGHT ] : [ Item ID ] = [ ' + itemId + ' ] ; [ WIDTH ] = [ ' + WIDTH + ' ] ; [ HEIGHT ] = [ ' + HEIGHT + ' ] ; [ ORIENTATION ] = [ ' + ORIENTATION + ' ]');
} // else
applyDimensions (catalog, itemId, ORIENTATION);
} // else
} // getDimensions
function applyDimensions(catalog, itemId, ORIENTATION){
if ( portfolio.getFieldDefinitions(catalog, [FIELD], false).length === 1 ) {
portfolio.log('[ updateAsset ] = [ ' + ORIENTATION + ' ]');
var updateJSON = {};
updateJSON[FIELD] = ORIENTATION;
portfolio.updateAsset(catalog, itemId, updateJSON);
} else {
portfolio.log('[ ERROR ! ] : Please ensure that the "' + FIELD + '" Custom Field has been created !');
} // else
portfolio.log('[ ' + DISPLAY_NAME + ' version ' + VERSION + ' ] - \\\\\\\\\\\\\\\\\\\\ END Job \\\\\\\\\\\\\\\\\\\\');
} // applyDimensions