From e9053970f96dd4517f0267fe007496bad970fd73 Mon Sep 17 00:00:00 2001 From: Mats Mikkel Rummelhoff Date: Mon, 26 Jun 2017 22:36:31 +0200 Subject: [PATCH] Adds support for Solspace Calendar 1.7.0+ --- reasons/ReasonsPlugin.php | 37 +++++++------------ ...a4e.js => reasons-557580bb0fb4a8808525.js} | 2 +- reasons/resources/rev-manifest.json | 2 +- source/javascripts/reasons.js | 18 ++++++--- 4 files changed, 28 insertions(+), 31 deletions(-) rename reasons/resources/javascripts/{reasons-a08bbfa4180502815a4e.js => reasons-557580bb0fb4a8808525.js} (79%) diff --git a/reasons/ReasonsPlugin.php b/reasons/ReasonsPlugin.php index 400df8b..60957b5 100644 --- a/reasons/ReasonsPlugin.php +++ b/reasons/ReasonsPlugin.php @@ -328,15 +328,6 @@ protected function getConditionals() $sources['globalSet:' . $globalSet->id] = $globalSet->fieldLayoutId; } - // Matrix blocks – TODO - // $matrixBlockTypeRecords = MatrixBlockTypeRecord::model()->findAll(); - // if ($matrixBlockTypeRecords) { - // foreach ($matrixBlockTypeRecords as $matrixBlockTypeRecord) { - // $matrixBlockType = MatrixBlockTypeModel::populateModel($matrixBlockTypeRecord); - // $sources['matrixBlockType:' . $matrixBlockType->id] = $matrixBlockType->fieldLayoutId; - // } - // } - // Users $usersFieldLayout = craft()->fields->getLayoutByType(ElementType::User); if ($usersFieldLayout) { @@ -346,24 +337,22 @@ protected function getConditionals() // Solspace Calendar $solspaceCalendarPlugin = craft()->plugins->getPlugin('calendar'); if ($solspaceCalendarPlugin && $solspaceCalendarPlugin->getDeveloper() === 'Solspace') { - $solspaceCalendarFieldLayout = craft()->fields->getLayoutByType('Calendar_Event'); - if ($solspaceCalendarFieldLayout) { - $sources['solspaceCalendar'] = $solspaceCalendarFieldLayout->id; + // Before 1.7.0, Solspace Calendar used a single Field Layout for all calendars. Let's try and support both the old and the new + if (version_compare($solspaceCalendarPlugin->getVersion(), '1.7.0', '>=')) { + $solspaceCalendars = craft()->calendar_calendars->getAllCalendars(); + if ($solspaceCalendars && is_array($solspaceCalendars) && !empty($solspaceCalendars)) { + foreach ($solspaceCalendars as $solspaceCalendar) { + $sources['solspaceCalendar:'.$solspaceCalendar->id] = $solspaceCalendar->fieldLayoutId; + } + } + } else { + $solspaceCalendarFieldLayout = craft()->fields->getLayoutByType('Calendar_Event'); + if ($solspaceCalendarFieldLayout) { + $sources['solspaceCalendar'] = $solspaceCalendarFieldLayout->id; + } } } - // Commerce – TODO - // $commercePlugin = craft()->plugins->getPlugin('commerce'); - // if ($commercePlugin && $commercePlugin->getDeveloper() === 'Pixel & Tonic') { - // // Product types - // $productTypes = craft()->commerce_productTypes->getAllProductTypes(); - // if ($productTypes) { - // foreach ($productTypes as $productType) { - // $sources['commerceProductType:'.$productType->id] = - // } - // } - // } - // Get all conditionals $conditionals = array(); $conditionalsRecords = Reasons_ConditionalsRecord::model()->findAll(); diff --git a/reasons/resources/javascripts/reasons-a08bbfa4180502815a4e.js b/reasons/resources/javascripts/reasons-557580bb0fb4a8808525.js similarity index 79% rename from reasons/resources/javascripts/reasons-a08bbfa4180502815a4e.js rename to reasons/resources/javascripts/reasons-557580bb0fb4a8808525.js index f6947df..491a70e 100644 --- a/reasons/resources/javascripts/reasons-a08bbfa4180502815a4e.js +++ b/reasons/resources/javascripts/reasons-557580bb0fb4a8808525.js @@ -1,4 +1,4 @@ -!function(e){function t(s){if(i[s])return i[s].exports;var n=i[s]={exports:{},id:s,loaded:!1};return e[s].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var i={};return t.m=e,t.c=i,t.p="javascripts/",t(0)}([function(e,t,i){e.exports=i(1)},function(e,t,i){"use strict";!function(e){return!!e.Craft&&void(Craft.ReasonsPlugin={FieldLayoutDesigner:i(2),ConditionalsRenderer:i(4),ASSET_SOURCE_HANDLE:"assetSource",CATEGORY_GROUP_HANDLE:"categoryGroup",TAG_GROUP_HANDLE:"tagGroup",GLOBAL_SET_HANDLE:"globalSet",ENTRY_TYPE_HANDLE:"entryType",SECTION_HANDLE:"section",USERS_HANDLE:"users",FIELDS_HANDLE:"field",SOLSPACE_CALENDAR_HANDLE:"solspaceCalendar",ASSET_SOURCE_ACTION:"assetSources/saveSource",CATEGORY_ACTION:"categories/saveCategory",CATEGORY_GROUP_ACTION:"categories/saveGroup",TAG_ACTION:"tagManager/saveTag",TAG_GROUP_ACTION:"tags/saveTagGroup",GLOBAL_SET_CONTENT_ACTION:"globals/saveContent",GLOBAL_SET_ACTION:"globals/saveSet",ENTRY_ACTION:"entries/saveEntry",ENTRY_TYPE_ACTION:"sections/saveEntryType",USERS_ACTION:"users/saveUser",USERS_FIELDS_ACTION:"users/saveFieldLayout",FIELDS_ACTION:"fields/saveField",SOLSPACE_CALENDAR_EVENTS_ACTION:"calendar/events/saveEvent",SOLSPACE_CALENDAR_SETTINGS_ACTION:"calendar/settings/saveSettings",RENDER_CONTEXT:"render",LAYOUT_DESIGNER_CONTEXT:"fld",FIELD_DESIGNER_CONTEXT:"field",init:function(e){this.data=e,this.initPrimaryForm()},initPrimaryForm:function(){this.destroyPrimaryForm();var e=Craft.cp.$primaryForm&&Craft.cp.$primaryForm.length?Craft.cp.$primaryForm:$("#content form:first");e&&e.length&&(this.primaryForm=this.initForm(e))},destroyPrimaryForm:function(){this.primaryForm&&(this.primaryForm.destroy(),delete this.primaryForm)},initElementEditor:function(e){var t=this.getConditionals(e);if(!t)return!1;var i=(new Date).getTime(),s=function(){var e=(new Date).getTime(),n=$(".elementeditor:last"),a=n.length>0&&n.closest(".hud"),r=!!(a&&a.length>0)&&a.data("elementEditor"),o=!!r&&r.$form;o?(r._reasonsForm=new this.ConditionalsRenderer(o,t),r.hud.on("hide",$.proxy(this.destroyElementEditorForm,this,r))):e-i<2e3&&Garnish.requestAnimationFrame(s)}.bind(this);s()},destroyElementEditorForm:function(e){var t=e._reasonsForm||null;t&&(t.destroy(),delete e._reasonsForm)},initForm:function(e){var t=this.getElementSourceFromForm(e),i=!!t&&this.getFormContext(e);if(!t||!i)return!1;var s=t.type+(t.id?":"+t.id:""),n=this.getConditionals(s);switch(i){case this.LAYOUT_DESIGNER_CONTEXT:return new this.FieldLayoutDesigner(e,n);case this.FIELD_DESIGNER_CONTEXT:return null;case this.RENDER_CONTEXT:return n?new this.ConditionalsRenderer(e,n):null}return null},getConditionals:function(e){return e?this.data.conditionals&&this.data.conditionals.hasOwnProperty(e)?this.data.conditionals[e]:null:this.data.conditionals||{}},getToggleFields:function(){return this.data.toggleFields?this.data.toggleFields:[]},getToggleFieldById:function(e){e=parseInt(e);for(var t=this.getToggleFields(),i=t.length,s=0;s0&&n.closest(".hud"),r=!!(a&&a.length>0)&&a.data("elementEditor"),o=!!r&&r.$form;o?(r._reasonsForm=new this.ConditionalsRenderer(o,t),r.hud.on("hide",$.proxy(this.destroyElementEditorForm,this,r))):e-i<2e3&&Garnish.requestAnimationFrame(s)}.bind(this);s()},destroyElementEditorForm:function(e){var t=e._reasonsForm||null;t&&(t.destroy(),delete e._reasonsForm)},initForm:function(e){var t=this.getElementSourceFromForm(e),i=!!t&&this.getFormContext(e);if(!t||!i)return!1;var s=t.type+(t.id?":"+t.id:""),n=this.getConditionals(s);switch(i){case this.LAYOUT_DESIGNER_CONTEXT:return new this.FieldLayoutDesigner(e,n);case this.FIELD_DESIGNER_CONTEXT:return null;case this.RENDER_CONTEXT:return n?new this.ConditionalsRenderer(e,n):null}return null},getConditionals:function(e){return e?this.data.conditionals&&this.data.conditionals.hasOwnProperty(e)?this.data.conditionals[e]:null:this.data.conditionals||{}},getToggleFields:function(){return this.data.toggleFields?this.data.toggleFields:[]},getToggleFieldById:function(e){e=parseInt(e);for(var t=this.getToggleFields(),i=t.length,s=0;s