2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * Modifications to the original nifi code for the ONAP project are made
18 * available under the Apache License, Version 2.0
21 /* global define, module, require, exports */
23 (function (root, factory) {
24 if (typeof define === 'function' && define.amd) {
33 'nf.FilteredDialogCommon',
36 function ($, Slick, nfClient, nfBirdseye, nfStorage, nfGraph, nfCanvasUtils, nfErrorHandler, nfFilteredDialogCommon, nfDialog, nfCommon) {
37 return (nf.ng.ProcessorComponent = factory($, Slick, nfClient, nfBirdseye, nfStorage, nfGraph, nfCanvasUtils, nfErrorHandler, nfFilteredDialogCommon, nfDialog, nfCommon));
39 } else if (typeof exports === 'object' && typeof module === 'object') {
40 module.exports = (nf.ng.ProcessorComponent =
41 factory(require('jquery'),
44 require('nf.Birdseye'),
45 require('nf.Storage'),
47 require('nf.CanvasUtils'),
48 require('nf.ErrorHandler'),
49 require('nf.FilteredDialogCommon'),
51 require('nf.Common')));
53 nf.ng.ProcessorComponent = factory(root.$,
61 root.nf.FilteredDialogCommon,
65 }(this, function ($, Slick, nfClient, nfBirdseye, nfStorage, nfGraph, nfCanvasUtils, nfErrorHandler, nfFilteredDialogCommon, nfDialog, nfCommon) {
68 return function (serviceProvider) {
74 var processorTypesData;
78 * Filters the processor type table.
80 var applyFilter = function () {
82 var processorTypesGrid = $('#processor-types-table').data('gridInstance');
84 // ensure the grid has been initialized
85 if (nfCommon.isDefinedAndNotNull(processorTypesGrid)) {
86 var processorTypesDataForFilter = processorTypesGrid.getData();
88 // update the search criteria
89 processorTypesDataForFilter.setFilterArgs({
90 searchString: getFilterText()
92 processorTypesDataForFilter.refresh();
94 // update the buttons to possibly trigger the disabled state
95 $('#new-processor-dialog').modal('refreshButtons');
97 // update the selection if possible
98 if (processorTypesDataForFilter.getLength() > 0) {
99 nfFilteredDialogCommon.choseFirstRow(processorTypesGrid);
100 // make the first row visible
101 processorTypesGrid.scrollRowToTop(0);
107 * Determines if the item matches the filter.
109 * @param {object} item The item to filter.
110 * @param {object} args The filter criteria.
111 * @returns {boolean} Whether the item matches the filter.
113 var matchesRegex = function (item, args) {
114 if (args.searchString === '') {
119 // perform the row filtering
120 var filterExp = new RegExp(args.searchString, 'i');
126 // determine if the item matches the filter
127 var matchesLabel = item['label'].search(filterExp) >= 0;
128 var matchesTags = item['tags'].search(filterExp) >= 0;
129 return matchesLabel || matchesTags;
133 * Performs the filtering.
135 * @param {object} item The item subject to filtering.
136 * @param {object} args Filter arguments.
137 * @returns {Boolean} Whether or not to include the item.
139 var filter = function (item, args) {
140 // determine if the item matches the filter
141 var matchesFilter = matchesRegex(item, args);
143 // determine if the row matches the selected tags
144 var matchesTags = true;
146 var tagFilters = $('#processor-tag-cloud').tagcloud('getSelectedTags');
147 var hasSelectedTags = tagFilters.length > 0;
148 if (hasSelectedTags) {
149 matchesTags = matchesSelectedTags(tagFilters, item['tags']);
153 // determine if the row matches the selected source group
154 var matchesGroup = true;
155 if (matchesFilter && matchesTags) {
156 var bundleGroup = $('#processor-bundle-group-combo').combo('getSelectedOption');
157 if (nfCommon.isDefinedAndNotNull(bundleGroup) && bundleGroup.value !== '') {
158 matchesGroup = (item.bundle.group === bundleGroup.value);
162 // determine if this row should be visible
163 var matches = matchesFilter && matchesTags && matchesGroup;
165 // if this row is currently selected and its being filtered
166 if (matches === false && $('#selected-processor-type').text() === item['type']) {
167 // clear the selected row
168 $('#processor-type-description').attr('title', '').text('');
169 $('#processor-type-name').attr('title', '').text('');
170 $('#processor-type-bundle').attr('title', '').text('');
171 $('#selected-processor-name').text('');
172 $('#selected-processor-type').text('').removeData('bundle');
174 // clear the active cell the it can be reselected when its included
175 var processTypesGrid = $('#processor-types-table').data('gridInstance');
176 processTypesGrid.resetActiveCell();
183 * Determines if the specified tags match all the tags selected by the user.
185 * @argument {string[]} tagFilters The tag filters.
186 * @argument {string} tags The tags to test.
188 var matchesSelectedTags = function (tagFilters, tags) {
189 var selectedTags = [];
190 $.each(tagFilters, function (_, filter) {
191 selectedTags.push(filter);
194 // normalize the tags
195 var normalizedTags = tags.toLowerCase();
198 $.each(selectedTags, function (i, selectedTag) {
199 if (normalizedTags.indexOf(selectedTag) === -1) {
209 * Get the text out of the filter field. If the filter field doesn't
210 * have any text it will contain the text 'filter list' so this method
213 var getFilterText = function () {
214 return $('#processor-type-filter').val();
218 * Resets the filtered processor types.
220 var resetProcessorDialog = function () {
222 //********* REPLICATED A BLOCK OF CODE to get logic of autoloading processor ---STARTING FROM HERE----********************
224 // initialize the processor type table
225 var processorTypesColumns = [
230 formatter: nfCommon.typeFormatter,
238 formatter: nfCommon.typeVersionFormatter,
248 formatter: nfCommon.genericValueFormatter
252 var processorTypesOptions = {
253 forceFitColumns: true,
254 enableTextSelectionOnCells: true,
255 enableCellNavigation: true,
256 enableColumnReorder: false,
262 // initialize the dataview
263 processorTypesData = new Slick.Data.DataView({
266 processorTypesData.setItems([]);
267 processorTypesData.setFilterArgs({
268 searchString: getFilterText()
270 processorTypesData.setFilter(filter);
272 // initialize the sort
276 }, processorTypesData);
278 // initialize the grid
279 var processorTypesGrid = new Slick.Grid('#processor-types-table', processorTypesData, processorTypesColumns, processorTypesOptions);
280 processorTypesGrid.setSelectionModel(new Slick.RowSelectionModel());
281 processorTypesGrid.registerPlugin(new Slick.AutoTooltips());
282 processorTypesGrid.setSortColumn('type', true);
283 processorTypesGrid.onSort.subscribe(function (e, args) {
285 columnId: args.sortCol.field,
286 sortAsc: args.sortAsc
287 }, processorTypesData);
289 processorTypesGrid.onSelectedRowsChanged.subscribe(function (e, args) {
290 if ($.isArray(args.rows) && args.rows.length === 1) {
291 var processorTypeIndex = args.rows[0];
292 var processorType = processorTypesGrid.getDataItem(processorTypeIndex);
294 // set the processor type description
295 if (nfCommon.isDefinedAndNotNull(processorType)) {
296 if (nfCommon.isBlank(processorType.description)) {
297 $('#processor-type-description')
299 .html('<span class="unset">No description specified</span>');
301 $('#processor-type-description')
302 .width($('#processor-description-container').innerWidth() - 1)
303 .html(processorType.description)
307 var bundle = nfCommon.formatBundle(processorType.bundle);
308 var type = nfCommon.formatType(processorType);
311 $('#processor-type-name').text(type).attr('title', type);
312 $('#processor-type-bundle').text(bundle).attr('title', bundle);
313 $('#selected-processor-name').text(processorType.label);
314 $('#selected-processor-type').text(processorType.type).data('bundle', processorType.bundle);
316 // refresh the buttons based on the current selection
317 $('#new-processor-dialog').modal('refreshButtons');
321 processorTypesGrid.onViewportChanged.subscribe(function (e, args) {
322 nfCommon.cleanUpTooltips($('#processor-types-table'), 'div.view-usage-restriction');
325 // wire up the dataview to the grid
326 processorTypesData.onRowCountChanged.subscribe(function (e, args) {
327 processorTypesGrid.updateRowCount();
328 processorTypesGrid.render();
330 // update the total number of displayed processors
331 $('#displayed-processor-types').text(args.current);
333 processorTypesData.onRowsChanged.subscribe(function (e, args) {
334 processorTypesGrid.invalidateRows(args.rows);
335 processorTypesGrid.render();
337 processorTypesData.syncGridSelection(processorTypesGrid, false);
339 // hold onto an instance of the grid
340 $('#processor-types-table').data('gridInstance', processorTypesGrid).on('mouseenter', 'div.slick-cell', function (e) {
341 var usageRestriction = $(this).find('div.view-usage-restriction');
342 if (usageRestriction.length && !usageRestriction.data('qtip')) {
343 var rowId = $(this).find('span.row-id').text();
345 // get the status item
346 var item = processorTypesData.getItemById(rowId);
349 if (item.restricted === true) {
350 var restrictionTip = $('<div></div>');
352 if (nfCommon.isBlank(item.usageRestriction)) {
353 restrictionTip.append($('<p style="margin-bottom: 3px;"></p>').text('Requires the following permissions:'));
355 restrictionTip.append($('<p style="margin-bottom: 3px;"></p>').text(item.usageRestriction + ' Requires the following permissions:'));
358 var restrictions = [];
359 if (nfCommon.isDefinedAndNotNull(item.explicitRestrictions)) {
360 $.each(item.explicitRestrictions, function (_, explicitRestriction) {
361 var requiredPermission = explicitRestriction.requiredPermission;
362 restrictions.push("'" + requiredPermission.label + "' - " + nfCommon.escapeHtml(explicitRestriction.explanation));
365 restrictions.push('Access to restricted components regardless of restrictions.');
367 restrictionTip.append(nfCommon.formatUnorderedList(restrictions));
369 usageRestriction.qtip($.extend({}, nfCommon.config.tooltipConfig, {
370 content: restrictionTip,
372 container: $('#summary'),
385 var generalRestriction = nfCommon.getPolicyTypeListing('restricted-components');
387 // load the available processor types, this select is shown in the
388 // new processor dialog when a processor is dragged onto the screen
391 url:'../nifi-api/flow/processor-types',
392 // url: serviceProvider.headerCtrl.toolboxCtrl.config.urls.processorTypes,
394 }).done(function (response) {
395 console.log(response);
397 var groups = d3.set();
398 var restrictedUsage = d3.map();
399 var requiredPermissions = d3.map();
402 processorTypesData.beginUpdate();
404 // go through each processor type
405 $.each(response.processorTypes, function (i, documentedType) {
406 var type = documentedType.type;
408 if (documentedType.restricted === true) {
409 if (nfCommon.isDefinedAndNotNull(documentedType.explicitRestrictions)) {
410 $.each(documentedType.explicitRestrictions, function (_, explicitRestriction) {
411 var requiredPermission = explicitRestriction.requiredPermission;
413 // update required permissions
414 if (!requiredPermissions.has(requiredPermission.id)) {
415 requiredPermissions.set(requiredPermission.id, requiredPermission.label);
418 // update component restrictions
419 if (!restrictedUsage.has(requiredPermission.id)) {
420 restrictedUsage.set(requiredPermission.id, []);
423 restrictedUsage.get(requiredPermission.id).push({
424 type: nfCommon.formatType(documentedType),
425 bundle: nfCommon.formatBundle(documentedType.bundle),
426 explanation: nfCommon.escapeHtml(explicitRestriction.explanation)
430 // update required permissions
431 if (!requiredPermissions.has(generalRestriction.value)) {
432 requiredPermissions.set(generalRestriction.value, generalRestriction.text);
435 // update component restrictions
436 if (!restrictedUsage.has(generalRestriction.value)) {
437 restrictedUsage.set(generalRestriction.value, []);
440 restrictedUsage.get(generalRestriction.value).push({
441 type: nfCommon.formatType(documentedType),
442 bundle: nfCommon.formatBundle(documentedType.bundle),
443 explanation: nfCommon.escapeHtml(documentedType.usageRestriction)
449 groups.add(documentedType.bundle.group);
451 // create the row for the processor type
452 processorTypesData.addItem({
454 label: nfCommon.substringAfterLast(type, '.'),
456 bundle: documentedType.bundle,
457 description: nfCommon.escapeHtml(documentedType.description),
458 restricted: documentedType.restricted,
459 usageRestriction: nfCommon.escapeHtml(documentedType.usageRestriction),
460 explicitRestrictions: documentedType.explicitRestrictions,
461 tags: documentedType.tags.join(', ')
464 // count the frequency of each tag for this type
465 $.each(documentedType.tags, function (i, tag) {
466 tags.push(tag.toLowerCase());
471 processorTypesData.endUpdate();
474 processorTypesData.reSort();
475 processorTypesGrid.invalidate();
477 // set the component restrictions and the corresponding required permissions
478 nfCanvasUtils.addComponentRestrictions(restrictedUsage, requiredPermissions);
480 // set the total number of processors
481 $('#total-processor-types, #displayed-processor-types').text(response.processorTypes.length);
483 // create the tag cloud
484 $('#processor-tag-cloud').tagcloud({
490 // build the combo options
495 groups.each(function (group) {
502 // initialize the bundle group combo
503 $('#processor-bundle-group-combo').combo({
507 }).fail(nfErrorHandler.handleAjaxError);
509 //************* REPLICATED CODE---ENDS HERE------******************
513 // clear the selected tag cloud
514 $('#processor-tag-cloud').tagcloud('clearSelectedTags');
516 // reset the group combo
517 $('#processor-bundle-group-combo').combo('setSelectedOption', {
521 // clear any filter strings
522 $('#processor-type-filter').val('');
524 // reapply the filter
527 // clear the selected row
528 $('#processor-type-description').attr('title', '').text('');
529 $('#processor-type-name').attr('title', '').text('');
530 $('#processor-type-bundle').attr('title', '').text('');
531 $('#selected-processor-name').text('');
532 $('#selected-processor-type').text('').removeData('bundle');
534 // unselect any current selection
535 var processTypesGrid = $('#processor-types-table').data('gridInstance');
536 processTypesGrid.setSelectedRows([]);
537 processTypesGrid.resetActiveCell();
541 * Create the processor and add to the graph.
543 * @argument {string} name The processor name.
544 * @argument {string} processorType The processor type.
545 * @argument {object} bundle The processor bundle.
546 * @argument {object} pt The point that the processor was dropped.
548 var createProcessor = function (name, processorType, bundle, pt) {
549 var processorEntity = {
550 'revision': nfClient.getRevision({
555 'disconnectedNodeAcknowledged': nfStorage.isDisconnectionAcknowledged(),
557 'type': processorType,
567 // create a new processor of the defined type
570 url: serviceProvider.headerCtrl.toolboxCtrl.config.urls.api + '/process-groups/' + encodeURIComponent(nfCanvasUtils.getGroupId()) + '/processors',
571 data: JSON.stringify(processorEntity),
573 contentType: 'application/json'
574 }).done(function (response) {
575 // add the processor to the graph
577 'processors': [response]
582 // update component visibility
583 nfGraph.updateVisibility();
585 // update the birdseye
586 nfBirdseye.refresh();
587 }).fail(nfErrorHandler.handleAjaxError);
591 * Whether the specified item is selectable.
593 * @param item process type
595 var isSelectable = function (item) {
596 return item.restricted === false || nfCommon.canAccessComponentRestrictions(item.explicitRestrictions);
599 function ProcessorComponent() {
601 this.icon = 'icon icon-processor';
603 this.hoverIcon = 'icon icon-processor-add';
606 * The processor component's modal.
611 * The processor component modal's filter.
616 * Initialize the filter.
619 // initialize the processor type table
620 var processorTypesColumns = [
625 formatter: nfCommon.typeFormatter,
633 formatter: nfCommon.typeVersionFormatter,
643 formatter: nfCommon.genericValueFormatter
647 var processorTypesOptions = {
648 forceFitColumns: true,
649 enableTextSelectionOnCells: true,
650 enableCellNavigation: true,
651 enableColumnReorder: false,
657 // initialize the dataview
658 processorTypesData = new Slick.Data.DataView({
661 processorTypesData.setItems([]);
662 processorTypesData.setFilterArgs({
663 searchString: getFilterText()
665 processorTypesData.setFilter(filter);
667 // initialize the sort
671 }, processorTypesData);
673 // initialize the grid
674 var processorTypesGrid = new Slick.Grid('#processor-types-table', processorTypesData, processorTypesColumns, processorTypesOptions);
675 processorTypesGrid.setSelectionModel(new Slick.RowSelectionModel());
676 processorTypesGrid.registerPlugin(new Slick.AutoTooltips());
677 processorTypesGrid.setSortColumn('type', true);
678 processorTypesGrid.onSort.subscribe(function (e, args) {
680 columnId: args.sortCol.field,
681 sortAsc: args.sortAsc
682 }, processorTypesData);
684 processorTypesGrid.onSelectedRowsChanged.subscribe(function (e, args) {
685 if ($.isArray(args.rows) && args.rows.length === 1) {
686 var processorTypeIndex = args.rows[0];
687 var processorType = processorTypesGrid.getDataItem(processorTypeIndex);
689 // set the processor type description
690 if (nfCommon.isDefinedAndNotNull(processorType)) {
691 if (nfCommon.isBlank(processorType.description)) {
692 $('#processor-type-description')
694 .html('<span class="unset">No description specified</span>');
696 $('#processor-type-description')
697 .width($('#processor-description-container').innerWidth() - 1)
698 .html(processorType.description)
702 var bundle = nfCommon.formatBundle(processorType.bundle);
703 var type = nfCommon.formatType(processorType);
706 $('#processor-type-name').text(type).attr('title', type);
707 $('#processor-type-bundle').text(bundle).attr('title', bundle);
708 $('#selected-processor-name').text(processorType.label);
709 $('#selected-processor-type').text(processorType.type).data('bundle', processorType.bundle);
711 // refresh the buttons based on the current selection
712 $('#new-processor-dialog').modal('refreshButtons');
716 processorTypesGrid.onViewportChanged.subscribe(function (e, args) {
717 nfCommon.cleanUpTooltips($('#processor-types-table'), 'div.view-usage-restriction');
720 // wire up the dataview to the grid
721 processorTypesData.onRowCountChanged.subscribe(function (e, args) {
722 processorTypesGrid.updateRowCount();
723 processorTypesGrid.render();
725 // update the total number of displayed processors
726 $('#displayed-processor-types').text(args.current);
728 processorTypesData.onRowsChanged.subscribe(function (e, args) {
729 processorTypesGrid.invalidateRows(args.rows);
730 processorTypesGrid.render();
732 processorTypesData.syncGridSelection(processorTypesGrid, false);
734 // hold onto an instance of the grid
735 $('#processor-types-table').data('gridInstance', processorTypesGrid).on('mouseenter', 'div.slick-cell', function (e) {
736 var usageRestriction = $(this).find('div.view-usage-restriction');
737 if (usageRestriction.length && !usageRestriction.data('qtip')) {
738 var rowId = $(this).find('span.row-id').text();
740 // get the status item
741 var item = processorTypesData.getItemById(rowId);
744 if (item.restricted === true) {
745 var restrictionTip = $('<div></div>');
747 if (nfCommon.isBlank(item.usageRestriction)) {
748 restrictionTip.append($('<p style="margin-bottom: 3px;"></p>').text('Requires the following permissions:'));
750 restrictionTip.append($('<p style="margin-bottom: 3px;"></p>').text(item.usageRestriction + ' Requires the following permissions:'));
753 var restrictions = [];
754 if (nfCommon.isDefinedAndNotNull(item.explicitRestrictions)) {
755 $.each(item.explicitRestrictions, function (_, explicitRestriction) {
756 var requiredPermission = explicitRestriction.requiredPermission;
757 restrictions.push("'" + requiredPermission.label + "' - " + nfCommon.escapeHtml(explicitRestriction.explanation));
760 restrictions.push('Access to restricted components regardless of restrictions.');
762 restrictionTip.append(nfCommon.formatUnorderedList(restrictions));
764 usageRestriction.qtip($.extend({}, nfCommon.config.tooltipConfig, {
765 content: restrictionTip,
767 container: $('#summary'),
780 var generalRestriction = nfCommon.getPolicyTypeListing('restricted-components');
782 // load the available processor types, this select is shown in the
783 // new processor dialog when a processor is dragged onto the screen
786 url:'../nifi-api/flow/processor-types',
787 // url: serviceProvider.headerCtrl.toolboxCtrl.config.urls.processorTypes,
789 }).done(function (response) {
790 console.log(response);
792 var groups = d3.set();
793 var restrictedUsage = d3.map();
794 var requiredPermissions = d3.map();
797 processorTypesData.beginUpdate();
799 // go through each processor type
800 $.each(response.processorTypes, function (i, documentedType) {
801 var type = documentedType.type;
803 if (documentedType.restricted === true) {
804 if (nfCommon.isDefinedAndNotNull(documentedType.explicitRestrictions)) {
805 $.each(documentedType.explicitRestrictions, function (_, explicitRestriction) {
806 var requiredPermission = explicitRestriction.requiredPermission;
808 // update required permissions
809 if (!requiredPermissions.has(requiredPermission.id)) {
810 requiredPermissions.set(requiredPermission.id, requiredPermission.label);
813 // update component restrictions
814 if (!restrictedUsage.has(requiredPermission.id)) {
815 restrictedUsage.set(requiredPermission.id, []);
818 restrictedUsage.get(requiredPermission.id).push({
819 type: nfCommon.formatType(documentedType),
820 bundle: nfCommon.formatBundle(documentedType.bundle),
821 explanation: nfCommon.escapeHtml(explicitRestriction.explanation)
825 // update required permissions
826 if (!requiredPermissions.has(generalRestriction.value)) {
827 requiredPermissions.set(generalRestriction.value, generalRestriction.text);
830 // update component restrictions
831 if (!restrictedUsage.has(generalRestriction.value)) {
832 restrictedUsage.set(generalRestriction.value, []);
835 restrictedUsage.get(generalRestriction.value).push({
836 type: nfCommon.formatType(documentedType),
837 bundle: nfCommon.formatBundle(documentedType.bundle),
838 explanation: nfCommon.escapeHtml(documentedType.usageRestriction)
844 groups.add(documentedType.bundle.group);
846 // create the row for the processor type
847 processorTypesData.addItem({
849 label: nfCommon.substringAfterLast(type, '.'),
851 bundle: documentedType.bundle,
852 description: nfCommon.escapeHtml(documentedType.description),
853 restricted: documentedType.restricted,
854 usageRestriction: nfCommon.escapeHtml(documentedType.usageRestriction),
855 explicitRestrictions: documentedType.explicitRestrictions,
856 tags: documentedType.tags.join(', ')
859 // count the frequency of each tag for this type
860 $.each(documentedType.tags, function (i, tag) {
861 tags.push(tag.toLowerCase());
866 processorTypesData.endUpdate();
869 processorTypesData.reSort();
870 processorTypesGrid.invalidate();
872 // set the component restrictions and the corresponding required permissions
873 nfCanvasUtils.addComponentRestrictions(restrictedUsage, requiredPermissions);
875 // set the total number of processors
876 $('#total-processor-types, #displayed-processor-types').text(response.processorTypes.length);
878 // create the tag cloud
879 $('#processor-tag-cloud').tagcloud({
885 // build the combo options
890 groups.each(function (group) {
897 // initialize the bundle group combo
898 $('#processor-bundle-group-combo').combo({
902 }).fail(nfErrorHandler.handleAjaxError);
907 * Gets the modal element.
909 * @returns {*|jQuery|HTMLElement}
911 getElement: function () {
912 return $('#new-processor-dialog');
916 * Initialize the modal.
921 // configure the new processor dialog
922 this.getElement().modal({
923 scrollableContentStyle: 'scrollable',
924 headerText: 'Add Processor',
926 resize: function () {
927 $('#processor-type-description')
928 .width($('#processor-description-container').innerWidth() - 1)
929 .text($('#processor-type-description').attr('title'))
937 * Updates the modal config.
939 * @param {string} name The name of the property to update.
940 * @param {object|array} config The config for the `name`.
942 update: function (name, config) {
943 this.getElement().modal(name, config);
950 this.getElement().modal('show');
957 this.getElement().modal('hide');
962 ProcessorComponent.prototype = {
963 constructor: ProcessorComponent,
966 * Gets the component.
968 * @returns {*|jQuery|HTMLElement}
970 getElement: function () {
971 return $('#processor-component');
975 * Enable the component.
977 enabled: function () {
978 this.getElement().attr('disabled', false);
982 * Disable the component.
984 disabled: function () {
985 this.getElement().attr('disabled', true);
989 * Handler function for when component is dropped on the canvas.
991 * @argument {object} pt The point that the component was dropped
993 dropHandler: function (pt) {
994 this.promptForProcessorType(pt);
998 * The drag icon for the toolbox component.
1001 * @returns {*|jQuery|HTMLElement}
1003 dragIcon: function (event) {
1004 return $('<div class="icon icon-processor-add"></div>');
1008 * Prompts the user to select the type of new processor to create.
1010 * @argument {object} pt The point that the processor was dropped
1012 promptForProcessorType: function (pt) {
1013 var processorComponent = this;
1015 // handles adding the selected processor at the specified point
1016 var addProcessor = function () {
1017 // get the type of processor currently selected
1018 var name = $('#selected-processor-name').text();
1019 var processorType = $('#selected-processor-type').text();
1020 var bundle = $('#selected-processor-type').data('bundle');
1022 // ensure something was selected
1023 if (name === '' || processorType === '') {
1024 nfDialog.showOkDialog({
1025 headerText: 'Add Processor',
1026 dialogContent: 'The type of processor to create must be selected.'
1029 // create the new processor
1030 createProcessor(name, processorType, bundle, pt);
1034 processorComponent.modal.hide();
1037 // get the grid reference
1038 var grid = $('#processor-types-table').data('gridInstance');
1039 var dataview = grid.getData();
1041 // add the processor when its double clicked in the table
1042 var gridDoubleClick = function (e, args) {
1043 var processorType = grid.getDataItem(args.row);
1045 if (isSelectable(processorType)) {
1046 $('#selected-processor-name').text(processorType.label);
1047 $('#selected-processor-type').text(processorType.type).data('bundle', processorType.bundle);
1053 // register a handler for double click events
1054 grid.onDblClick.subscribe(gridDoubleClick);
1056 // update the button model
1057 this.modal.update('setButtonModel', [{
1064 disabled: function () {
1065 var selected = grid.getSelectedRows();
1067 if (selected.length > 0) {
1068 // grid configured with multi-select = false
1069 var item = grid.getDataItem(selected[0]);
1070 return isSelectable(item) === false;
1072 return dataview.getLength() === 0;
1080 buttonText: 'Cancel',
1087 click: function () {
1088 $('#new-processor-dialog').modal('hide');
1093 // set a new handler for closing the the dialog
1094 this.modal.update('setCloseHandler', function () {
1095 // remove the handler
1096 grid.onDblClick.unsubscribe(gridDoubleClick);
1098 // clear the current filters
1099 resetProcessorDialog();
1105 var navigationKeys = [$.ui.keyCode.UP, $.ui.keyCode.PAGE_UP, $.ui.keyCode.DOWN, $.ui.keyCode.PAGE_DOWN];
1108 $('#processor-type-filter').off('keyup').on('keyup', function (e) {
1109 var code = e.keyCode ? e.keyCode : e.which;
1111 // ignore navigation keys
1112 if ($.inArray(code, navigationKeys) !== -1) {
1116 if (code === $.ui.keyCode.ENTER) {
1117 var selected = grid.getSelectedRows();
1119 if (selected.length > 0) {
1120 // grid configured with multi-select = false
1121 var item = grid.getDataItem(selected[0]);
1122 if (isSelectable(item)) {
1131 // setup row navigation
1132 nfFilteredDialogCommon.addKeydownListener('#processor-type-filter', grid, dataview);
1134 // adjust the grid canvas now that its been rendered
1135 grid.resizeCanvas();
1137 // auto select the first row if possible
1138 if (dataview.getLength() > 0) {
1139 nfFilteredDialogCommon.choseFirstRow(grid);
1142 // set the initial focus
1143 $('#processor-type-filter').focus()
1147 var processorComponent = new ProcessorComponent();
1148 return processorComponent;