AfformGui - Improve dragging & dropping with more space & clearer borders
[civicrm-core.git] / ext / afform / admin / ang / afGuiEditor / elements / afGuiContainer.component.js
index 236a99aaedf050d55d7f88ce64c8e227854c57b7..0b4d6a4d019d2f8a919756141866340fba1d6d0c 100644 (file)
@@ -12,7 +12,7 @@
     },
     require: {editor: '^^afGuiEditor'},
     controller: function($scope, crmApi4, dialogService, afGui) {
-      var ts = $scope.ts = CRM.ts(),
+      var ts = $scope.ts = CRM.ts('org.civicrm.afform_admin'),
         ctrl = this;
 
       this.$onInit = function() {
           if (blockTag && (blockTag in afGui.meta.blocks) && !afGui.meta.blocks[blockTag].layout) {
             ctrl.loading = true;
             crmApi4('Afform', 'loadAdminData', {
-              definition: {name: afGui.meta.blocks[blockTag].name}
+              definition: {name: afGui.meta.blocks[blockTag].name},
+              skipEntities: _.transform(afGui.meta.entities, function(result, entity, entityName) {
+                if (entity.fields) {
+                  result.push(entityName);
+                }
+              }, [])
             }, 0).then(function(data) {
               afGui.addMeta(data);
               initializeBlockContainer();
         }
       };
 
+      this.sortableOptions = {
+        handle: '.af-gui-bar',
+        connectWith: '[ui-sortable]',
+        cancel: 'input,textarea,button,select,option,a,.dropdown-menu',
+        placeholder: 'af-gui-dropzone',
+        containment: '#afGuiEditor-canvas-body'
+      };
+
       $scope.isSelectedFieldset = function(entityName) {
         return entityName === ctrl.editor.getSelectedEntityName();
       };
         };
 
         _.each(afGui.meta.blocks, function(blockInfo, directive) {
-          if (directive === ctrl.node['#tag'] || blockInfo.join === ctrl.getFieldEntityType()) {
+          if (directive === ctrl.node['#tag'] || (blockInfo.join && blockInfo.join === ctrl.getFieldEntityType())) {
             block.options.push({
               id: directive,
               text: blockInfo.title
         var model = {
           title: '',
           name: null,
+          type: 'block',
           layout: ctrl.node['#children']
         };
         if (ctrl.join) {
           model.block = afGui.meta.blocks[$scope.block.original].block;
         }
         else {
-          model.block = ctrl.container.getFieldEntityType() || '*';
+          model.block = ctrl.getFieldEntityType();
         }
         dialogService.open('saveBlockDialog', '~/afGuiEditor/saveBlock.html', model, options)
           .then(function(block) {
               }
             });
           }
-          if (!entityType && afGui.getField(searchDisplay['saved_search.api_entity'], fieldName)) {
+          if (!entityType && fieldName && afGui.getField(searchDisplay['saved_search.api_entity'], fieldName)) {
             entityType = searchDisplay['saved_search.api_entity'];
           }
           if (entityType) {
             return false;
           }
         });
-        return entityType;
+        return entityType || _.map(afGui.meta.searchDisplays, 'saved_search.api_entity')[0];
       };
 
     }