diff --git a/src/components/com_tjucm/administrator/houseKeeping/1.2.4/updateAlias.php b/src/components/com_tjucm/administrator/houseKeeping/1.2.4/updateAlias.php index 735b74fc..95c61ddc 100644 --- a/src/components/com_tjucm/administrator/houseKeeping/1.2.4/updateAlias.php +++ b/src/components/com_tjucm/administrator/houseKeeping/1.2.4/updateAlias.php @@ -55,23 +55,22 @@ public function migrate() foreach ($ucmTypes as $ucmType) { $ucmTypeTable = JTable::getInstance('Type', 'TjucmTable', array('dbo', $db)); + $ucmTypeTable->load($ucmType->id); // Remove white spaces in alias of UCM types $updatedAlias = JFilterOutput::stringURLSafe($ucmTypeTable->alias); - $oldAlias = $ucmTypeTable->alias; $ucmTypeTable->alias = $updatedAlias; $ucmTypeTable->store(); - - $result['status'] = ''; - $result['message'] = "Migration in progress"; } } // Get all the menus of UCM types + $query = $db->getQuery(true); + $query->select('*'); $query->from($db->quoteName('#__menu')); $query->where( - $db->quoteName(link) . "=" . $db->quote('index.php?option=com_tjucm&view=itemform') . - "||" . $db->quoteName(link) . "=" . $db->quote('index.php?option=com_tjucm&view=items') + $db->quoteName('link') . "=" . $db->quote('index.php?option=com_tjucm&view=itemform') . + "||" . $db->quoteName('link') . "=" . $db->quote('index.php?option=com_tjucm&view=items') ); $db->setQuery($query); $menuItems = $db->loadObjectlist(); @@ -81,14 +80,17 @@ public function migrate() foreach ($menuItems as $menuItem) { $menuItemTable = JTable::getInstance('Menu', 'MenusTable', array('dbo', $db)); + $menuItemTable->load($menuItem->id); $oldparams = json_decode($menuItemTable->params); // Remove white spaces in alias of menus - $oldparams->ucm_type = JFilterOutput::stringURLSafe($oldparams->ucm_type); + if (isset($oldparams->ucm_type)) + { + $oldparams->ucm_type = JFilterOutput::stringURLSafe($oldparams->ucm_type); + } + $menuItemTable->params = json_encode($oldparams); $menuItemTable->store(); - $result['status'] = ''; - $result['message'] = "Migration in progress"; } } @@ -101,6 +103,7 @@ public function migrate() $result['status'] = false; $result['message'] = $e->getMessage(); } + return $result; } } diff --git a/src/components/com_tjucm/administrator/models/type.php b/src/components/com_tjucm/administrator/models/type.php index 4ab8f1d2..d5723981 100644 --- a/src/components/com_tjucm/administrator/models/type.php +++ b/src/components/com_tjucm/administrator/models/type.php @@ -40,6 +40,22 @@ class TjucmModelType extends JModelAdmin */ protected $item = null; + /** + * Constructor. + * + * @param array $config An optional associative array of configuration settings. + * + * @see JController + * @since 1.6 + */ + public function __construct($config = array()) + { + $config['event_after_delete'] = 'tjUcmOnAfterTypeDelete'; + $config['event_change_state'] = 'tjUcmOnAfterTypeChangeState'; + + parent::__construct($config); + } + /** * Returns a reference to the a Table object, always creating it. * @@ -351,6 +367,13 @@ public function save($data) if (parent::save($data)) { + $id = (int) $this->getState($this->getName() . '.id'); + $data['typeId'] = $id; + $dispatcher = JDispatcher::getInstance(); + JPluginHelper::importPlugin('actionlog', 'tjucm'); + $isNew = ($data['id'] != 0) ? false : true; + $dispatcher->trigger('tjUcmOnAfterTypeSave', array($data, $isNew)); + return true; } diff --git a/src/components/com_tjucm/languages/site/en-GB/en-GB.com_tjucm.ini b/src/components/com_tjucm/languages/site/en-GB/en-GB.com_tjucm.ini index af1b82f5..037d7831 100644 --- a/src/components/com_tjucm/languages/site/en-GB/en-GB.com_tjucm.ini +++ b/src/components/com_tjucm/languages/site/en-GB/en-GB.com_tjucm.ini @@ -42,7 +42,6 @@ COM_TJUCM_NO_ITEM_SELECTED="No items selected" COM_TJUCM_SAVE_SUCCESS="Item successfully saved" COM_TJUCM_ITEM_ID_SELECT_LABEL="Select the item ID" COM_TJUCM_SELECT_UCM_TYPE_LBL="UCM Type" -COM_TJUCM_SELECT_UCM_TYPE_DESC="Select UCM Type" COM_TJUCM_FIELDSET_UCM_TYPE_SELECT_LABEL="UCM Config" COM_TJUCM_FILTER_SELECT_LABEL=" - Select %s - " COM_TJUCM_TEST_LABEL="Test label" @@ -211,3 +210,7 @@ COM_TJUCM_ITEMS_IMPORTED_SCUUESSFULLY="%d record(s) imported successfully" COM_TJUCM_ITEMS_IMPORT_REJECTED_RECORDS="%d invalid record(s) were not imported" COM_TJUCM_ITEMS_NO_RECORDS_TO_IMPORT="No records found to import" COM_TJUCM_ITEMS_IMPORTING_MSG="Please wait, Records are being imported..." +COM_TJUCM_LOGIN_MSG="Please login" +COM_TJUCM_SELECT_SOURCE_FORM="Select data source" +COM_TJUCM_PROCESS_DATA="Process" +COM_TJUCM_CANCEL_COPY="Cancel" diff --git a/src/components/com_tjucm/media/css/tjucm.css b/src/components/com_tjucm/media/css/tjucm.css index 5641015a..325dc8f4 100644 --- a/src/components/com_tjucm/media/css/tjucm.css +++ b/src/components/com_tjucm/media/css/tjucm.css @@ -22,3 +22,12 @@ width:200px !important; .tjucm-wrapper .tj-wordwrap{ word-break: break-word; } + +#item-form #tjucm_loader{ + height:auto; + position:absolute; + top:45%; + left:45%; + opacity: 0.5; + display:none; +} diff --git a/src/components/com_tjucm/media/gif/.htaccess b/src/components/com_tjucm/media/gif/.htaccess new file mode 100755 index 00000000..79a12fe2 --- /dev/null +++ b/src/components/com_tjucm/media/gif/.htaccess @@ -0,0 +1,3 @@ + + Allow from All + \ No newline at end of file diff --git a/src/components/com_tjucm/media/gif/loading.gif b/src/components/com_tjucm/media/gif/loading.gif new file mode 100644 index 00000000..b8e5a75f Binary files /dev/null and b/src/components/com_tjucm/media/gif/loading.gif differ diff --git a/src/components/com_tjucm/media/js/ui/itemform.js b/src/components/com_tjucm/media/js/ui/itemform.js index c73b926e..1ca1043c 100644 --- a/src/components/com_tjucm/media/js/ui/itemform.js +++ b/src/components/com_tjucm/media/js/ui/itemform.js @@ -302,7 +302,7 @@ jQuery(window).load(function() tjUcmClickedOnPrev = 0; } - jQuery("html, body").animate({scrollTop: jQuery("#item-form").position().top}, "slow"); + jQuery("html, body").animate({scrollTop: jQuery("#system-message-container").position().top}, "slow"); } } else @@ -334,7 +334,7 @@ jQuery(window).load(function() tjUcmClickedOnPrev = 0; } - jQuery("html, body").animate({scrollTop: jQuery("#item-form").position().top}, "slow"); + jQuery("html, body").animate({scrollTop: jQuery("#system-message-container").position().top}, "slow"); } }); }); @@ -558,11 +558,14 @@ var tjUcmItemForm = { else if(jQuery(fieldObj).hasClass('tjfieldTjList')) { /* This condition used for tjlist option actial values updated - This is used for single & multiple values*/ - if (jQuery(fieldObj).val() !='' && jQuery(fieldObj).val() != undefined) { tjUcmItemFieldFormData.append(jQuery(fieldObj).attr('name'), jQuery(fieldObj).val()); } + else + { + tjUcmItemFieldFormData.append(jQuery(fieldObj).attr('name'), ''); + } /* Check other options multiple values exist and its not empty */ if (jQuery('input#'+jQuery(fieldObj).attr('id')).val() !='' && jQuery('input#'+jQuery(fieldObj).attr('id')).val() != undefined) @@ -585,13 +588,20 @@ var tjUcmItemForm = { tjUcmItemFieldFormData.append(jQuery(fieldObj).attr('name'), jQuery(fieldObj).val()); } } - else if (jQuery(fieldObj).attr('type') != 'file') + else if (jQuery(fieldObj).attr('type') == 'file') { - tjUcmItemFieldFormData.append(jQuery(fieldObj).attr('name'), jQuery(fieldObj).val()); + tjUcmItemFieldFormData.append(jQuery(fieldObj).attr('name'), jQuery(fieldObj)[0].files[0]); } else { - tjUcmItemFieldFormData.append(jQuery(fieldObj).attr('name'), jQuery(fieldObj)[0].files[0]); + if (jQuery(fieldObj).val() == null) + { + tjUcmItemFieldFormData.append(jQuery(fieldObj).attr('name'), ''); + } + else + { + tjUcmItemFieldFormData.append(jQuery(fieldObj).attr('name'), jQuery(fieldObj).val()); + } } // Call function if field name exist in request data @@ -603,6 +613,10 @@ var tjUcmItemForm = { return true; }, afterDataSave: function (error, response){ + + /* Hide loader when record is saved*/ + jQuery("#item-form #tjucm_loader").hide(); + response = JSON.parse(response); /* Remove the dirty class fromt the form once the field data is saved*/ jQuery('#item-form').removeClass('dirty'); @@ -675,7 +689,7 @@ var tjUcmItemForm = { Joomla.renderMessages({'error':[response.message]}); } - jQuery("html, body").animate({scrollTop: jQuery("#item-form").position().top}, "slow"); + jQuery("html, body").animate({scrollTop: jQuery("#system-message-container").position().top}, "slow"); } if (response.messages !== null) @@ -686,7 +700,7 @@ var tjUcmItemForm = { Joomla.renderMessages({'error':[value]}); }); - jQuery("html, body").animate({scrollTop: jQuery("#item-form").position().top}, "slow"); + jQuery("html, body").animate({scrollTop: jQuery("#system-message-container").position().top}, "slow"); } } } @@ -769,7 +783,7 @@ var tjUcmItemForm = { { tjUcmItemForm.setVisibilityOfNavigationButtons(); jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr('disabled', false); - jQuery("html, body").animate({scrollTop: jQuery("#item-form").position().top}, "slow"); + jQuery("html, body").animate({scrollTop: jQuery("#system-message-container").position().top}, "slow"); return false; } @@ -787,6 +801,10 @@ var tjUcmItemForm = { this.click(); }); + /* Show loader when record is saved*/ + jQuery("#item-form #tjucm_loader").show(); + jQuery("html, body").animate({scrollTop: jQuery("#item-form #tjucm_loader").position().top}, "slow"); + tjUcmItemForm.getUcmParentRecordId(tjUcmSaveRecordAsDraft, function (){ var tjUcmForm = document.getElementById('item-form'); var tjUcmItemFormData = new FormData(tjUcmForm); @@ -815,7 +833,7 @@ var tjUcmItemForm = { /* Reset the variable*/ tjUcmFormSubmitCallingButtonId = ''; - jQuery('input[type="checkbox"]').each(function (){ + jQuery('#item-form input[type="checkbox"]').each(function (){ if (jQuery(this).prop('checked') == true) { tjUcmItemFormData.append(jQuery(this).attr('name'), 1); @@ -826,6 +844,13 @@ var tjUcmItemForm = { } }); + jQuery('#item-form select').each(function (){ + if (jQuery(this).val() == null) + { + tjUcmItemFormData.append(jQuery(this).attr('name'), ''); + } + }); + /* Do not show draft save msg if the save is triggered as per bitrate config*/ if (tjUcmSaveFormInDraftWithNoMsg !== undefined) { @@ -897,7 +922,6 @@ var tjUcmItemForm = { /* Disable the save button till the record is saved*/ jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr('disabled', true); - tjUcmItemForm.getUcmParentRecordId(1, function (){ tjUcmSectionFormData.delete('task'); tjUcmSectionFormData.delete('option'); @@ -917,7 +941,7 @@ var tjUcmItemForm = { } else { - jQuery("html, body").animate({scrollTop: jQuery("#item-form").position().top}, "slow"); + jQuery("html, body").animate({scrollTop: jQuery("#system-message-container").position().top}, "slow"); return false; } @@ -1007,7 +1031,7 @@ function steppedFormSave(form_id, status, showDraftSuccessMsg) if(!confirm(Joomla.JText._("COM_TJUCM_ITEMFORM_SUBMIT_ALERT"))) { jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr('disabled', false); - jQuery("html, body").animate({scrollTop: jQuery("#item-form").position().top}, "slow"); + jQuery("html, body").animate({scrollTop: jQuery("#system-message-container").position().top}, "slow"); return false; } @@ -1018,7 +1042,7 @@ function steppedFormSave(form_id, status, showDraftSuccessMsg) else { jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr('disabled', false); - jQuery("html, body").animate({scrollTop: jQuery("#item-form").position().top}, "slow"); + jQuery("html, body").animate({scrollTop: jQuery("#system-message-container").position().top}, "slow"); return false; } @@ -1040,7 +1064,7 @@ function steppedFormSave(form_id, status, showDraftSuccessMsg) Joomla.renderMessages({'error':[value]}); }); - jQuery("html, body").animate({scrollTop: jQuery("#item-form").position().top}, "slow"); + jQuery("html, body").animate({scrollTop: jQuery("#system-message-container").position().top}, "slow"); } } @@ -1048,7 +1072,7 @@ function steppedFormSave(form_id, status, showDraftSuccessMsg) { Joomla.renderMessages({'info':[returnedData.message]}); - jQuery("html, body").animate({scrollTop: jQuery("#item-form").position().top}, "slow"); + jQuery("html, body").animate({scrollTop: jQuery("#system-message-container").position().top}, "slow"); } if (returnedData.data !== null) diff --git a/src/components/com_tjucm/media/js/ui/itemform.min.js b/src/components/com_tjucm/media/js/ui/itemform.min.js index f042679a..25388259 100644 --- a/src/components/com_tjucm/media/js/ui/itemform.min.js +++ b/src/components/com_tjucm/media/js/ui/itemform.min.js @@ -1 +1 @@ -var tjucmRelatedFieldUpdatedOptions="",tjUcmTinyMCEFieldIds=new Array,tjUcmClickedOnNext=0,tjUcmClickedOnPrev=0,tjUcmCurrentAutoSaveState=0,tjUcmFormFinalSave=0,tjUcmJCEFieldIds=new Array,tjUcmFormSavedByBitRateConfig=0,tjUcmSaveFormInDraftWithNoMsg=void 0,tjUcmFormSubmitCallingButtonId="";jQuery(window).load(function(){var t=Number(jQuery("#itemState").val()),e=jQuery("#item-form #tjucm-bitrate").val(),r=jQuery("#item-form #tjucm-bitrate_seconds").val();if(1===t){var a=jQuery("#item-form #tjucm-autosave").val();e=jQuery("#item-form #tjucm-bitrate").val(),r=jQuery("#item-form #tjucm-bitrate_seconds").val();if(1==a){if(tjUcmCurrentAutoSaveState=1,jQuery("#item-form").on("change select",":input",function(){tjUcmCurrentAutoSaveState&&tjUcmItemForm.onUcmFormChange(this)}),jQuery("#item-form .field-calendar input:text").blur(function(){tjUcmCurrentAutoSaveState&&tjUcmItemForm.onUcmFormChange(this)}),jQuery("#item-form .js-editor-tinymce").length>0){var i=Joomla.getOptions("plg_editor_tinymce");null!=i&&jQuery.each(i.tinyMCE,function(t,e){if(jQuery("#item-form #jform_"+t).length){var r=jQuery("#jform_"+t+"_ifr").contents().find("body").html();tjUcmTinyMCEFieldIds[t]=r}else if(0==jQuery("#item-form #jform_"+t).length&&"default"!=t){var a=jQuery("textarea[id$='__"+t+"']");a.length&&jQuery.each(a,function(t,e){var r=jQuery(e).attr("id"),a=jQuery("#"+r+"_ifr").contents().find("body").html(),i=r.replace("jform_","");tjUcmTinyMCEFieldIds[i]=a})}})}jQuery("#item-form .wf-editor-container").length>0&&setTimeout(function(){jQuery("#item-form .mceIframeContainer iframe").each(function(){var t=jQuery(this).attr("id"),e=t.replace("jform_","").replace("_ifr",""),r=jQuery("#"+t).contents().find("body").html();tjUcmJCEFieldIds[e]=r})},2e3),1==a&&1==e&&void 0!==r&&jQuery("#item-form #tjUcmSectionDraftSave").length>=1&&setInterval(function(){for(var t in(jQuery("#item-form").hasClass("dirty")||0===tjUcmFormSavedByBitRateConfig)&&(tjUcmFormSavedByBitRateConfig=1,jQuery("#tjUcmSectionDraftSave").click()),tjUcmJCEFieldIds)if(tjUcmJCEFieldIds.hasOwnProperty(t)){var e=jQuery("#jform_"+t+"_ifr").contents().find("body").html();if(tjUcmJCEFieldIds[t]!=e){var r=jQuery("#jform_"+t);r.length&&(r.val(e),tjUcmJCEFieldIds[t]=e,tjUcmItemForm.onUcmFormChange(r))}}if(jQuery("#item-form .js-editor-tinymce").length>0)for(var t in tjUcmTinyMCEFieldIds)if(tjUcmTinyMCEFieldIds.hasOwnProperty(t)){var a=jQuery("#jform_"+t+"_ifr").contents().find("body").html();if(tjUcmTinyMCEFieldIds[t]!=a){var i=jQuery("#jform_"+t);i.length&&(i.val(a),tjUcmTinyMCEFieldIds[t]=a,tjUcmItemForm.onUcmFormChange(i))}}},1e3*r)}}else jQuery("#tjucm-auto-save-disabled-msg").show();jQuery("#tjucm_myTabTabs a").on("click",function(){jQuery(this).parent().next("li").length?jQuery("#next_button").attr("disabled",!1):jQuery("#next_button").attr("disabled",!0),jQuery(this).parent().prev("li").length?jQuery("#previous_button").attr("disabled",!1):jQuery("#previous_button").attr("disabled",!0)}),jQuery(document).on("subform-row-add",function(t,e){var r,a=jQuery(e).attr("data-group").replace(jQuery(e).attr("data-base-name"),"");if(jQuery(e).find(".js-editor-tinymce textarea")&&(r=jQuery(e).find(".js-editor-tinymce textarea").attr("id"))){var i=jQuery("#"+r+"_ifr").contents().find("body").html();r=r.replace("jform_",""),tjUcmTinyMCEFieldIds[r]=i}if(jQuery(e).find(".wf-editor-container textarea")&&(r=jQuery(e).find(".wf-editor-container textarea").attr("id"))){i=jQuery("#"+r+"_ifr").contents().find("body").html();r=r.replace("jform_",""),tjUcmTinyMCEFieldIds[r]=i}jQuery.each(tjucmRelatedFieldUpdatedOptions,function(t,r){if(r.templateId){var i=r.templateId.replace("XXX_XXX",a);jQuery(e).find("#"+i).html(""),jQuery.each(r.options,function(t,r){jQuery(e).find("#"+i).append('")}),jQuery(e).find("#"+i).trigger("liszt:updated")}})}),jQuery("#next_button, #previous_button").on("click",function(){if("next_button"==jQuery(this).attr("id")?tjUcmClickedOnNext=1:tjUcmClickedOnPrev=1,jQuery("#item-form").hasClass("dirty"))if(tjUcmCurrentAutoSaveState){var t=jQuery(jQuery("#tjucm_myTabTabs > .active a").attr("href")).find("input, textarea, select, fieldset");tjUcmItemForm.validateSection(t)?tjUcmItemForm.saveSectionData(jQuery("#tjucm_myTabTabs > .active a").attr("href")):(tjUcmClickedOnNext=0,tjUcmClickedOnPrev=0)}else{t=jQuery(jQuery("#tjucm_myTabTabs > .active a").attr("href")).find("input, textarea, select, fieldset");tjUcmItemForm.validateSection(t)?(jQuery("#system-message-container").html(""),tjUcmClickedOnNext&&(tjUcmClickedOnNext=0,jQuery("#tjucm_myTabTabs > .active").next("li").find("a").trigger("click"),tjUcmItemForm.setVisibilityOfNavigationButtons()),tjUcmClickedOnPrev&&(tjUcmClickedOnPrev=0,jQuery("#tjucm_myTabTabs > .active").prev("li").find("a").trigger("click"),tjUcmItemForm.setVisibilityOfNavigationButtons())):(tjUcmClickedOnNext=0,tjUcmClickedOnPrev=0),jQuery("html, body").animate({scrollTop:jQuery("#item-form").position().top},"slow")}else{t=jQuery(jQuery("#tjucm_myTabTabs > .active a").attr("href")).find("input, textarea, select, fieldset");tjUcmItemForm.validateSection(t)?(jQuery("#system-message-container").html(""),tjUcmClickedOnNext&&(tjUcmClickedOnNext=0,jQuery("#tjucm_myTabTabs > .active").next("li").find("a").trigger("click"),tjUcmItemForm.setVisibilityOfNavigationButtons()),tjUcmClickedOnPrev&&(tjUcmClickedOnPrev=0,jQuery("#tjucm_myTabTabs > .active").prev("li").find("a").trigger("click"),tjUcmItemForm.setVisibilityOfNavigationButtons())):(tjUcmClickedOnNext=0,tjUcmClickedOnPrev=0),jQuery("html, body").animate({scrollTop:jQuery("#item-form").position().top},"slow")}})});var tjUcmItemForm={getUcmParentRecordId:function(t,e){var r=jQuery("#item-form").find("input[name='jform[client]']").val();new Promise(function(e,a){var i=jQuery("#item-form").find("input[name='jform[id]']").val();if(""==i){var n=new FormData;""!=r&&n.append("client",r),n.append(Joomla.getOptions("csrf.token"),1);n.append("draft",t),com_tjucm.Services.Item.create(n,function(t,r){if(r=JSON.parse(r),null==t)if(null!==r.data&&jQuery.isNumeric(r.data.id)){jQuery("#item-form").find("input[name='jform[id]']").val(r.data.id);var i=window.location.href.split("#")[0],n=-1===i.indexOf("?")?"?":"&",o="id="+r.data.id;i.indexOf(o)>=0||(i+=n+o),history.pushState(null,null,i),e(r.data.id)}else a(r)})}else jQuery.isNumeric(i)&&0!=i&&e(i)}).then(function(t){e(t)}).catch(function(t){return console.log(t),!1})},onUcmFormChange:function(t){jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!0),tjUcmItemForm.getUcmParentRecordId(1,function(e){var r=jQuery("#item-form").find("input[name='jform[client]']").val();tjUcmItemForm.initUcmFormFieldDataSave(t,r,e)})},initUcmFormFieldDataSave:function(t,e,r){jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!0);var a="",i=new FormData;if(i.append(Joomla.getOptions("csrf.token"),1),void 0!==jQuery(t).parent().parent().parent().attr("data-base-name")||void 0!==jQuery(t).parent().parent().parent().parent().attr("data-base-name")){var n=jQuery(t).parent().parent().parent().attr("data-base-name");null==n&&(n=jQuery(t).parent().parent().parent().parent().attr("data-base-name"));var o=jQuery(t).attr("id"),m="com_tjucm."+(a=o.replace(o.split("_").pop(),"contentid")).split("__").pop().replace("_contentid","").replace("com_tjucm_",""),u=jQuery("#"+a).val();if(""==u){i.append("parent_id",r),i.append("client",m),i.append("draft",1),com_tjucm.Services.Item.create(i,function(o,u){if(u=JSON.parse(u),null==o)return null!==u.data&&jQuery.isNumeric(u.data.id)&&jQuery("#"+a).val(u.data.id),i.append("jform["+n+"]",m),i.append("client",e),i.append("recordid",r),com_tjucm.Services.Item.saveFieldData(i,function(e,r){var a=jQuery(t).attr("name"),i="[]"==a.slice(-2)?"[]":"",n="jform["+jQuery(t).attr("id").split("__").pop()+"]"+i;"radio"==jQuery(t).attr("type")&&(n="jform["+jQuery(t).attr("name").split("][").pop()),jQuery(t).attr("name",n),tjUcmItemForm.saveUcmFormFieldData(m,u.data.id,t),jQuery(t).attr("name",a)}),!0})}else{if(jQuery.isNumeric(u)&&0!=u){var c=jQuery(t).attr("name"),l="[]"==c.slice(-2)?"[]":"",d="jform["+jQuery(t).attr("id").split("__").pop()+"]"+l;if("radio"==jQuery(t).attr("type"))d="jform["+jQuery(t).attr("name").split("][").pop();return jQuery(t).attr("name",d),tjUcmItemForm.saveUcmFormFieldData(m,u,t),jQuery(t).attr("name",c),!0}null==u&&(tjUcmSaveFormInDraftWithNoMsg=1,tjUcmFormSubmitCallingButtonId="tjUcmSectionDraftSave",jQuery("#tjUcmSectionDraftSave").click())}return!1}return tjUcmItemForm.saveUcmFormFieldData(e,r,t),!0},saveUcmFormFieldData:function(t,e,r){jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!0);var a=new FormData;return a.append(Joomla.getOptions("csrf.token"),1),a.append("client",t),a.append("recordid",e),"checkbox"==jQuery(r).attr("type")?1==jQuery(r).prop("checked")?a.append(jQuery(r).attr("name"),1):a.append(jQuery(r).attr("name"),0):jQuery(r).hasClass("tjfieldTjList")?(""!=jQuery(r).val()&&null!=jQuery(r).val()&&a.append(jQuery(r).attr("name"),jQuery(r).val()),""!=jQuery("input#"+jQuery(r).attr("id")).val()&&null!=jQuery("input#"+jQuery(r).attr("id")).val()&&a.append(jQuery(r).attr("name"),jQuery("input#"+jQuery(r).attr("id")).val())):"tagsinput"==jQuery("input#"+jQuery(r).attr("id")).data("role")?(""!=jQuery("#"+jQuery(r).attr("id")).val()&&null!=jQuery("#"+jQuery(r).attr("id")).val()&&a.append(jQuery(r).attr("name"),jQuery("#"+jQuery(r).attr("id")).val()),""!=jQuery(r).val()&&null!=jQuery(r).val()&&a.append(jQuery(r).attr("name"),jQuery(r).val())):"file"!=jQuery(r).attr("type")?a.append(jQuery(r).attr("name"),jQuery(r).val()):a.append(jQuery(r).attr("name"),jQuery(r)[0].files[0]),""!=jQuery(r).attr("name")&&null!=jQuery(r).attr("name")&&com_tjucm.Services.Item.saveFieldData(a,tjUcmItemForm.afterDataSave),!0},afterDataSave:function(t,e){if(e=JSON.parse(e),jQuery("#item-form").removeClass("dirty"),null==e)return!1;if(jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!1),null!=e.data&&e.data.childContentIds&&jQuery.each(e.data.childContentIds,function(t,e){jQuery("#"+t).val(e)}),e.data&&tjUcmFormFinalSave&&(jQuery("#tjucm-auto-save-disabled-msg").show(),jQuery("#itemState").val(0),jQuery("#tjUcmSectionDraftSave").remove(),tjUcmCurrentAutoSaveState=0,tjUcmFormFinalSave=0),tjUcmClickedOnNext&&(tjUcmClickedOnNext=0,jQuery("#tjucm_myTabTabs > .active").next("li").find("a").trigger("click")),tjUcmClickedOnPrev&&(tjUcmClickedOnPrev=0,jQuery("#tjucm_myTabTabs > .active").prev("li").find("a").trigger("click")),tjUcmItemForm.setVisibilityOfNavigationButtons(),e.data){var r=jQuery("#item-form").find("input[name='jform[client]']").val(),a=jQuery("#item-form").find("input[name='jform[id]']").val();tjUcmItemForm.updateRelatedFieldsOptions(r,a)}tjUcmItemForm.renderResponseMessages(e)},renderResponseMessages:function(t){null!=t&&(null!==t.message&&(t.data?Joomla.renderMessages({success:[t.message]}):Joomla.renderMessages({error:[t.message]}),jQuery("html, body").animate({scrollTop:jQuery("#item-form").position().top},"slow")),null!==t.messages&&null!==t.messages.error&&(jQuery.each(t.messages.error,function(t,e){Joomla.renderMessages({error:[e]})}),jQuery("html, body").animate({scrollTop:jQuery("#item-form").position().top},"slow")))},updateRelatedFieldsOptions:function(t,e){var r=new FormData;r.append("client",t),r.append("content_id",e),com_tjucm.Services.Item.getUpdatedRelatedFieldsOptions(r,function(t,e){if(e=JSON.parse(e),""==(tjucmRelatedFieldUpdatedOptions=e.data))return!1;jQuery.each(e.data,function(t,e){jQuery("#"+e.elementId).html(""),jQuery.each(e.options,function(t,r){var a="";"1"==r.selected&&(a=' selected="selected" '),jQuery("#"+e.elementId).append('")}),jQuery("#"+e.elementId).trigger("liszt:updated")})})},saveUcmFormData:function(){jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!0),void 0===event?(tjUcmFormSubmitCallingButtonId="tjUcmSectionDraftSave",tjUcmSaveFormInDraftWithNoMsg=1):tjUcmFormSubmitCallingButtonId="tjUcmSectionDraftSave"==event.target.id||"tjUcmSectionFinalSave"==event.target.id?event.target.id:"tjUcmSectionDraftSave";var t=1;if("tjUcmSectionFinalSave"==tjUcmFormSubmitCallingButtonId){if(!document.formvalidator.isValid(document.getElementById("item-form")))return tjUcmItemForm.setVisibilityOfNavigationButtons(),jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!1),jQuery("html, body").animate({scrollTop:jQuery("#item-form").position().top},"slow"),!1;if(!confirm(Joomla.JText._("COM_TJUCM_ITEMFORM_SUBMIT_ALERT")))return jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!1),!1;jQuery("#system-message-container").html(""),jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!0),t=0}jQuery("#item-form .toggle-editor a").each(function(t){this.click()}),jQuery("#item-form .wf-editor-toggle").each(function(t){this.click()}),tjUcmItemForm.getUcmParentRecordId(t,function(){var t=document.getElementById("item-form"),e=new FormData(t);e.delete("task"),e.delete("option"),e.delete("view"),e.delete("layout");var r=jQuery("#item-form").find("input[name='jform[client]']").val(),a=jQuery("#item-form").find("input[name='jform[id]']").val();e.append(Joomla.getOptions("csrf.token"),1),e.append("client",r),e.append("recordid",a),"tjUcmSectionDraftSave"==tjUcmFormSubmitCallingButtonId&&e.append("draft",1),"tjUcmSectionFinalSave"==tjUcmFormSubmitCallingButtonId&&(tjUcmFormFinalSave=1),tjUcmFormSubmitCallingButtonId="",jQuery('input[type="checkbox"]').each(function(){1==jQuery(this).prop("checked")?e.append(jQuery(this).attr("name"),1):e.append(jQuery(this).attr("name"),0)}),void 0!==tjUcmSaveFormInDraftWithNoMsg&&(tjUcmSaveFormInDraftWithNoMsg=void 0,e.append("showDraftMessage",0)),com_tjucm.Services.Item.saveFormData(e,tjUcmItemForm.afterDataSave)}),jQuery("#item-form .toggle-editor a").each(function(t){this.click()}),jQuery("#item-form .wf-editor-toggle").each(function(t){this.click()})},saveSectionData:function(t){jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!0);var e=new FormData,r=jQuery(t).find("input, textarea, select, fieldset");if(!tjUcmItemForm.validateSection(r))return jQuery("html, body").animate({scrollTop:jQuery("#item-form").position().top},"slow"),!1;jQuery("#system-message-container").html(""),jQuery("#item-form .toggle-editor a").each(function(t){this.click()}),r.length&&r.each(function(){"file"==jQuery(this).attr("type")?null!=jQuery(this)[0].files[0]&&e.append(jQuery(this).attr("name"),jQuery(this)[0].files[0]):"checkbox"==jQuery(this).attr("type")?1==jQuery(this).prop("checked")?jQuery(this).val(1):jQuery(this).val(0):null!=jQuery(this).val()&&e.append(jQuery(this).attr("name"),jQuery(this).val())}),jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!0),tjUcmItemForm.getUcmParentRecordId(1,function(){e.delete("task"),e.delete("option"),e.delete("view"),e.delete("layout");var r=jQuery("#item-form").find("input[name='jform[client]']").val(),a=jQuery("#item-form").find("input[name='jform[id]']").val();e.append(Joomla.getOptions("csrf.token"),1),e.append("client",r),e.append("recordid",a),e.append("tjUcmFormSection",jQuery("a[href='"+t+"']").html()),com_tjucm.Services.Item.saveFormData(e,tjUcmItemForm.afterDataSave)})},validateSection:function(t){var e,r,a,i,n,o=!0,m=[];for(i=0,n=t.length;i0){for(e=Joomla.JText._("JLIB_FORM_FIELD_INVALID"),r={error:[]},i=m.length-1;i>=0;i--)(a=jQuery(m[i]).data("label"))&&r.error.push(e+a.text().replace("*",""));Joomla.renderMessages(r)}return o},setVisibilityOfNavigationButtons:function(){var t=jQuery("#tjucm_myTabTabs").find("li.active");jQuery(t).length&&(jQuery(t).next("li").length?jQuery("#next_button").attr("disabled",!1):jQuery("#next_button").attr("disabled",!0),jQuery(t).prev("li").length?jQuery("#previous_button").attr("disabled",!1):jQuery("#previous_button").attr("disabled",!0))}};function steppedFormSave(t,e,r){window.onbeforeunload=null,jQuery("#item-form .toggle-editor a").each(function(t){this.click()});var a=jQuery("#"+t),i=!1;if(jQuery("#form_status").val(e),"save"==e){if(!document.formvalidator.isValid("#item-form"))return jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!1),jQuery("html, body").animate({scrollTop:jQuery("#item-form").position().top},"slow"),!1;if(!confirm(Joomla.JText._("COM_TJUCM_ITEMFORM_SUBMIT_ALERT")))return jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!1),jQuery("html, body").animate({scrollTop:jQuery("#item-form").position().top},"slow"),!1;jQuery("#item-form").removeClass("dirty")}return a&&jQuery(a).ajaxSubmit({datatype:"JSON",async:!1,success:function(t){var a=JSON.parse(t);if(null!==a.messages&&null!==a.messages.error&&(jQuery.each(a.messages.error,function(t,e){Joomla.renderMessages({error:[e]})}),jQuery("html, body").animate({scrollTop:jQuery("#item-form").position().top},"slow")),null!==a.message&&""!=a.message&&(Joomla.renderMessages({info:[a.message]}),jQuery("html, body").animate({scrollTop:jQuery("#item-form").position().top},"slow")),null!==a.data){jQuery("#recordId").val(a.data.id),"save"==e?(jQuery("#tjUcmSectionFinalSave").attr("disabled","disabled"),Joomla.renderMessages({success:[Joomla.JText._("COM_TJUCM_MSG_ON_SAVED_FORM")]}),jQuery("html, body").animate({scrollTop:jQuery("#system-message-container").offset().top-40},"slow")):(i=!0,"1"===r&&(jQuery("#draft_msg").show(),setTimeout(function(){jQuery("#draft_msg").hide()},5e3)));var n=window.location.href.split("#")[0],o=-1===n.indexOf("?")?"?":"&",m="id="+a.data.id;jQuery.each(a.data.childContentIds,function(t,e){jQuery("input[name='"+e.elementName+"']").val(e.content_id)}),tjucmRelatedFieldUpdatedOptions=a.data.relatedFieldOptions,jQuery.each(a.data.relatedFieldOptions,function(t,e){jQuery("#"+e.elementId).html(""),jQuery.each(e.options,function(t,r){var a="";"1"==r.selected&&(a=' selected="selected" '),jQuery("#"+e.elementId).append('")}),jQuery("#"+e.elementId).trigger("liszt:updated")}),n.indexOf(m)>=0||(n+=o+m),history.pushState(null,null,n)}jQuery("#tjUcmSectionDraftSave").attr("disabled",!1),jQuery("#tjUcmSectionFinalSave").attr("disabled",!1),jQuery("#item-form .toggle-editor a").each(function(t){this.click()})}}),i}function itemformactions(t,e){var r=jQuery("ul#tjucm_myTabTabs").find("li.active a");null==jQuery(r).next("li")?jQuery("#previous_button").attr("disabled",!0):jQuery("#previous_button").attr("disabled",!1),null==jQuery(r).prev("li")?jQuery("#next_button").attr("disabled",!0):jQuery("#next_button").attr("disabled",!1),next?jQuery("#tjucm_myTabTabs > .active").next("li").find("a").trigger("click"):jQuery("#tjucm_myTabTabs > .active").next("li").prev("a").trigger("click");var a=jQuery("ul#"+getTabId).find("li.active").next("li").children("a").attr("href"),i=jQuery("ul#"+getTabId).find("li.active").prev("li").children("a").attr("href");null==a?jQuery("#next_button").attr("disabled",!0):jQuery("#next_button").attr("disabled",!1),null==i?jQuery("#previous_button").attr("disabled",!0):jQuery("#previous_button").attr("disabled",!1),steppedFormSave("item-form","draft",1),"next"==e&&jQuery("#"+getTabId+" > .active").next("li").find("a").trigger("click"),"prev"==e&&jQuery("#"+getTabId+" > .active").prev("li").find("a").trigger("click")} \ No newline at end of file +var tjucmRelatedFieldUpdatedOptions="",tjUcmTinyMCEFieldIds=new Array,tjUcmClickedOnNext=0,tjUcmClickedOnPrev=0,tjUcmCurrentAutoSaveState=0,tjUcmFormFinalSave=0,tjUcmJCEFieldIds=new Array,tjUcmFormSavedByBitRateConfig=0,tjUcmSaveFormInDraftWithNoMsg=void 0,tjUcmFormSubmitCallingButtonId="";jQuery(window).load(function(){var e=Number(jQuery("#itemState").val()),t=jQuery("#item-form #tjucm-bitrate").val(),r=jQuery("#item-form #tjucm-bitrate_seconds").val();if(1===e){var a=jQuery("#item-form #tjucm-autosave").val();t=jQuery("#item-form #tjucm-bitrate").val(),r=jQuery("#item-form #tjucm-bitrate_seconds").val();if(1==a){if(tjUcmCurrentAutoSaveState=1,jQuery("#item-form").on("change select",":input",function(){tjUcmCurrentAutoSaveState&&tjUcmItemForm.onUcmFormChange(this)}),jQuery("#item-form .field-calendar input:text").blur(function(){tjUcmCurrentAutoSaveState&&tjUcmItemForm.onUcmFormChange(this)}),jQuery("#item-form .js-editor-tinymce").length>0){var i=Joomla.getOptions("plg_editor_tinymce");null!=i&&jQuery.each(i.tinyMCE,function(e,t){if(jQuery("#item-form #jform_"+e).length){var r=jQuery("#jform_"+e+"_ifr").contents().find("body").html();tjUcmTinyMCEFieldIds[e]=r}else if(0==jQuery("#item-form #jform_"+e).length&&"default"!=e){var a=jQuery("textarea[id$='__"+e+"']");a.length&&jQuery.each(a,function(e,t){var r=jQuery(t).attr("id"),a=jQuery("#"+r+"_ifr").contents().find("body").html(),i=r.replace("jform_","");tjUcmTinyMCEFieldIds[i]=a})}})}jQuery("#item-form .wf-editor-container").length>0&&setTimeout(function(){jQuery("#item-form .mceIframeContainer iframe").each(function(){var e=jQuery(this).attr("id"),t=e.replace("jform_","").replace("_ifr",""),r=jQuery("#"+e).contents().find("body").html();tjUcmJCEFieldIds[t]=r})},2e3),1==a&&1==t&&void 0!==r&&jQuery("#item-form #tjUcmSectionDraftSave").length>=1&&setInterval(function(){for(var e in(jQuery("#item-form").hasClass("dirty")||0===tjUcmFormSavedByBitRateConfig)&&(tjUcmFormSavedByBitRateConfig=1,jQuery("#tjUcmSectionDraftSave").click()),tjUcmJCEFieldIds)if(tjUcmJCEFieldIds.hasOwnProperty(e)){var t=jQuery("#jform_"+e+"_ifr").contents().find("body").html();if(tjUcmJCEFieldIds[e]!=t){var r=jQuery("#jform_"+e);r.length&&(r.val(t),tjUcmJCEFieldIds[e]=t,tjUcmItemForm.onUcmFormChange(r))}}if(jQuery("#item-form .js-editor-tinymce").length>0)for(var e in tjUcmTinyMCEFieldIds)if(tjUcmTinyMCEFieldIds.hasOwnProperty(e)){var a=jQuery("#jform_"+e+"_ifr").contents().find("body").html();if(tjUcmTinyMCEFieldIds[e]!=a){var i=jQuery("#jform_"+e);i.length&&(i.val(a),tjUcmTinyMCEFieldIds[e]=a,tjUcmItemForm.onUcmFormChange(i))}}},1e3*r)}}else jQuery("#tjucm-auto-save-disabled-msg").show();jQuery("#tjucm_myTabTabs a").on("click",function(){jQuery(this).parent().next("li").length?jQuery("#next_button").attr("disabled",!1):jQuery("#next_button").attr("disabled",!0),jQuery(this).parent().prev("li").length?jQuery("#previous_button").attr("disabled",!1):jQuery("#previous_button").attr("disabled",!0)}),jQuery(document).on("subform-row-add",function(e,t){var r,a=jQuery(t).attr("data-group").replace(jQuery(t).attr("data-base-name"),"");if(jQuery(t).find(".js-editor-tinymce textarea")&&(r=jQuery(t).find(".js-editor-tinymce textarea").attr("id"))){var i=jQuery("#"+r+"_ifr").contents().find("body").html();r=r.replace("jform_",""),tjUcmTinyMCEFieldIds[r]=i}if(jQuery(t).find(".wf-editor-container textarea")&&(r=jQuery(t).find(".wf-editor-container textarea").attr("id"))){i=jQuery("#"+r+"_ifr").contents().find("body").html();r=r.replace("jform_",""),tjUcmTinyMCEFieldIds[r]=i}jQuery.each(tjucmRelatedFieldUpdatedOptions,function(e,r){if(r.templateId){var i=r.templateId.replace("XXX_XXX",a);jQuery(t).find("#"+i).html(""),jQuery.each(r.options,function(e,r){jQuery(t).find("#"+i).append('")}),jQuery(t).find("#"+i).trigger("liszt:updated")}})}),jQuery("#next_button, #previous_button").on("click",function(){if("next_button"==jQuery(this).attr("id")?tjUcmClickedOnNext=1:tjUcmClickedOnPrev=1,jQuery("#item-form").hasClass("dirty"))if(tjUcmCurrentAutoSaveState){var e=jQuery(jQuery("#tjucm_myTabTabs > .active a").attr("href")).find("input, textarea, select, fieldset");tjUcmItemForm.validateSection(e)?tjUcmItemForm.saveSectionData(jQuery("#tjucm_myTabTabs > .active a").attr("href")):(tjUcmClickedOnNext=0,tjUcmClickedOnPrev=0)}else{e=jQuery(jQuery("#tjucm_myTabTabs > .active a").attr("href")).find("input, textarea, select, fieldset");tjUcmItemForm.validateSection(e)?(jQuery("#system-message-container").html(""),tjUcmClickedOnNext&&(tjUcmClickedOnNext=0,jQuery("#tjucm_myTabTabs > .active").next("li").find("a").trigger("click"),tjUcmItemForm.setVisibilityOfNavigationButtons()),tjUcmClickedOnPrev&&(tjUcmClickedOnPrev=0,jQuery("#tjucm_myTabTabs > .active").prev("li").find("a").trigger("click"),tjUcmItemForm.setVisibilityOfNavigationButtons())):(tjUcmClickedOnNext=0,tjUcmClickedOnPrev=0),jQuery("html, body").animate({scrollTop:jQuery("#system-message-container").position().top},"slow")}else{e=jQuery(jQuery("#tjucm_myTabTabs > .active a").attr("href")).find("input, textarea, select, fieldset");tjUcmItemForm.validateSection(e)?(jQuery("#system-message-container").html(""),tjUcmClickedOnNext&&(tjUcmClickedOnNext=0,jQuery("#tjucm_myTabTabs > .active").next("li").find("a").trigger("click"),tjUcmItemForm.setVisibilityOfNavigationButtons()),tjUcmClickedOnPrev&&(tjUcmClickedOnPrev=0,jQuery("#tjucm_myTabTabs > .active").prev("li").find("a").trigger("click"),tjUcmItemForm.setVisibilityOfNavigationButtons())):(tjUcmClickedOnNext=0,tjUcmClickedOnPrev=0),jQuery("html, body").animate({scrollTop:jQuery("#system-message-container").position().top},"slow")}})});var tjUcmItemForm={getUcmParentRecordId:function(e,t){var r=jQuery("#item-form").find("input[name='jform[client]']").val();new Promise(function(t,a){var i=jQuery("#item-form").find("input[name='jform[id]']").val();if(""==i){var n=new FormData;""!=r&&n.append("client",r),n.append(Joomla.getOptions("csrf.token"),1);n.append("draft",e),com_tjucm.Services.Item.create(n,function(e,r){if(r=JSON.parse(r),null==e)if(null!==r.data&&jQuery.isNumeric(r.data.id)){jQuery("#item-form").find("input[name='jform[id]']").val(r.data.id);var i=window.location.href.split("#")[0],n=-1===i.indexOf("?")?"?":"&",o="id="+r.data.id;i.indexOf(o)>=0||(i+=n+o),history.pushState(null,null,i),t(r.data.id)}else a(r)})}else jQuery.isNumeric(i)&&0!=i&&t(i)}).then(function(e){t(e)}).catch(function(e){return console.log(e),!1})},onUcmFormChange:function(e){jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!0),tjUcmItemForm.getUcmParentRecordId(1,function(t){var r=jQuery("#item-form").find("input[name='jform[client]']").val();tjUcmItemForm.initUcmFormFieldDataSave(e,r,t)})},initUcmFormFieldDataSave:function(e,t,r){jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!0);var a="",i=new FormData;if(i.append(Joomla.getOptions("csrf.token"),1),void 0!==jQuery(e).parent().parent().parent().attr("data-base-name")||void 0!==jQuery(e).parent().parent().parent().parent().attr("data-base-name")){var n=jQuery(e).parent().parent().parent().attr("data-base-name");null==n&&(n=jQuery(e).parent().parent().parent().parent().attr("data-base-name"));var o=jQuery(e).attr("id"),m="com_tjucm."+(a=o.replace(o.split("_").pop(),"contentid")).split("__").pop().replace("_contentid","").replace("com_tjucm_",""),u=jQuery("#"+a).val();if(""==u){i.append("parent_id",r),i.append("client",m),i.append("draft",1),com_tjucm.Services.Item.create(i,function(o,u){if(u=JSON.parse(u),null==o)return null!==u.data&&jQuery.isNumeric(u.data.id)&&jQuery("#"+a).val(u.data.id),i.append("jform["+n+"]",m),i.append("client",t),i.append("recordid",r),com_tjucm.Services.Item.saveFieldData(i,function(t,r){var a=jQuery(e).attr("name"),i="[]"==a.slice(-2)?"[]":"",n="jform["+jQuery(e).attr("id").split("__").pop()+"]"+i;"radio"==jQuery(e).attr("type")&&(n="jform["+jQuery(e).attr("name").split("][").pop()),jQuery(e).attr("name",n),tjUcmItemForm.saveUcmFormFieldData(m,u.data.id,e),jQuery(e).attr("name",a)}),!0})}else{if(jQuery.isNumeric(u)&&0!=u){var c=jQuery(e).attr("name"),l="[]"==c.slice(-2)?"[]":"",d="jform["+jQuery(e).attr("id").split("__").pop()+"]"+l;if("radio"==jQuery(e).attr("type"))d="jform["+jQuery(e).attr("name").split("][").pop();return jQuery(e).attr("name",d),tjUcmItemForm.saveUcmFormFieldData(m,u,e),jQuery(e).attr("name",c),!0}null==u&&(tjUcmSaveFormInDraftWithNoMsg=1,tjUcmFormSubmitCallingButtonId="tjUcmSectionDraftSave",jQuery("#tjUcmSectionDraftSave").click())}return!1}return tjUcmItemForm.saveUcmFormFieldData(t,r,e),!0},saveUcmFormFieldData:function(e,t,r){jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!0);var a=new FormData;return a.append(Joomla.getOptions("csrf.token"),1),a.append("client",e),a.append("recordid",t),"checkbox"==jQuery(r).attr("type")?1==jQuery(r).prop("checked")?a.append(jQuery(r).attr("name"),1):a.append(jQuery(r).attr("name"),0):jQuery(r).hasClass("tjfieldTjList")?(""!=jQuery(r).val()&&null!=jQuery(r).val()?a.append(jQuery(r).attr("name"),jQuery(r).val()):a.append(jQuery(r).attr("name"),""),""!=jQuery("input#"+jQuery(r).attr("id")).val()&&null!=jQuery("input#"+jQuery(r).attr("id")).val()&&a.append(jQuery(r).attr("name"),jQuery("input#"+jQuery(r).attr("id")).val())):"tagsinput"==jQuery("input#"+jQuery(r).attr("id")).data("role")?(""!=jQuery("#"+jQuery(r).attr("id")).val()&&null!=jQuery("#"+jQuery(r).attr("id")).val()&&a.append(jQuery(r).attr("name"),jQuery("#"+jQuery(r).attr("id")).val()),""!=jQuery(r).val()&&null!=jQuery(r).val()&&a.append(jQuery(r).attr("name"),jQuery(r).val())):"file"==jQuery(r).attr("type")?a.append(jQuery(r).attr("name"),jQuery(r)[0].files[0]):null==jQuery(r).val()?a.append(jQuery(r).attr("name"),""):a.append(jQuery(r).attr("name"),jQuery(r).val()),""!=jQuery(r).attr("name")&&null!=jQuery(r).attr("name")&&com_tjucm.Services.Item.saveFieldData(a,tjUcmItemForm.afterDataSave),!0},afterDataSave:function(e,t){if(jQuery("#item-form #tjucm_loader").hide(),t=JSON.parse(t),jQuery("#item-form").removeClass("dirty"),null==t)return!1;if(jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!1),null!=t.data&&t.data.childContentIds&&jQuery.each(t.data.childContentIds,function(e,t){jQuery("#"+e).val(t)}),t.data&&tjUcmFormFinalSave&&(jQuery("#tjucm-auto-save-disabled-msg").show(),jQuery("#itemState").val(0),jQuery("#tjUcmSectionDraftSave").remove(),tjUcmCurrentAutoSaveState=0,tjUcmFormFinalSave=0),tjUcmClickedOnNext&&(tjUcmClickedOnNext=0,jQuery("#tjucm_myTabTabs > .active").next("li").find("a").trigger("click")),tjUcmClickedOnPrev&&(tjUcmClickedOnPrev=0,jQuery("#tjucm_myTabTabs > .active").prev("li").find("a").trigger("click")),tjUcmItemForm.setVisibilityOfNavigationButtons(),t.data){var r=jQuery("#item-form").find("input[name='jform[client]']").val(),a=jQuery("#item-form").find("input[name='jform[id]']").val();tjUcmItemForm.updateRelatedFieldsOptions(r,a)}tjUcmItemForm.renderResponseMessages(t)},renderResponseMessages:function(e){null!=e&&(null!==e.message&&(e.data?Joomla.renderMessages({success:[e.message]}):Joomla.renderMessages({error:[e.message]}),jQuery("html, body").animate({scrollTop:jQuery("#system-message-container").position().top},"slow")),null!==e.messages&&null!==e.messages.error&&(jQuery.each(e.messages.error,function(e,t){Joomla.renderMessages({error:[t]})}),jQuery("html, body").animate({scrollTop:jQuery("#system-message-container").position().top},"slow")))},updateRelatedFieldsOptions:function(e,t){var r=new FormData;r.append("client",e),r.append("content_id",t),com_tjucm.Services.Item.getUpdatedRelatedFieldsOptions(r,function(e,t){if(t=JSON.parse(t),""==(tjucmRelatedFieldUpdatedOptions=t.data))return!1;jQuery.each(t.data,function(e,t){jQuery("#"+t.elementId).html(""),jQuery.each(t.options,function(e,r){var a="";"1"==r.selected&&(a=' selected="selected" '),jQuery("#"+t.elementId).append('")}),jQuery("#"+t.elementId).trigger("liszt:updated")})})},saveUcmFormData:function(){jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!0),void 0===event?(tjUcmFormSubmitCallingButtonId="tjUcmSectionDraftSave",tjUcmSaveFormInDraftWithNoMsg=1):tjUcmFormSubmitCallingButtonId="tjUcmSectionDraftSave"==event.target.id||"tjUcmSectionFinalSave"==event.target.id?event.target.id:"tjUcmSectionDraftSave";var e=1;if("tjUcmSectionFinalSave"==tjUcmFormSubmitCallingButtonId){if(!document.formvalidator.isValid(document.getElementById("item-form")))return tjUcmItemForm.setVisibilityOfNavigationButtons(),jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!1),jQuery("html, body").animate({scrollTop:jQuery("#system-message-container").position().top},"slow"),!1;if(!confirm(Joomla.JText._("COM_TJUCM_ITEMFORM_SUBMIT_ALERT")))return jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!1),!1;jQuery("#system-message-container").html(""),jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!0),e=0}jQuery("#item-form .toggle-editor a").each(function(e){this.click()}),jQuery("#item-form .wf-editor-toggle").each(function(e){this.click()}),jQuery("#item-form #tjucm_loader").show(),jQuery("html, body").animate({scrollTop:jQuery("#item-form #tjucm_loader").position().top},"slow"),tjUcmItemForm.getUcmParentRecordId(e,function(){var e=document.getElementById("item-form"),t=new FormData(e);t.delete("task"),t.delete("option"),t.delete("view"),t.delete("layout");var r=jQuery("#item-form").find("input[name='jform[client]']").val(),a=jQuery("#item-form").find("input[name='jform[id]']").val();t.append(Joomla.getOptions("csrf.token"),1),t.append("client",r),t.append("recordid",a),"tjUcmSectionDraftSave"==tjUcmFormSubmitCallingButtonId&&t.append("draft",1),"tjUcmSectionFinalSave"==tjUcmFormSubmitCallingButtonId&&(tjUcmFormFinalSave=1),tjUcmFormSubmitCallingButtonId="",jQuery('#item-form input[type="checkbox"]').each(function(){1==jQuery(this).prop("checked")?t.append(jQuery(this).attr("name"),1):t.append(jQuery(this).attr("name"),0)}),jQuery("#item-form select").each(function(){null==jQuery(this).val()&&t.append(jQuery(this).attr("name"),"")}),void 0!==tjUcmSaveFormInDraftWithNoMsg&&(tjUcmSaveFormInDraftWithNoMsg=void 0,t.append("showDraftMessage",0)),com_tjucm.Services.Item.saveFormData(t,tjUcmItemForm.afterDataSave)}),jQuery("#item-form .toggle-editor a").each(function(e){this.click()}),jQuery("#item-form .wf-editor-toggle").each(function(e){this.click()})},saveSectionData:function(e){jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!0);var t=new FormData,r=jQuery(e).find("input, textarea, select, fieldset");if(!tjUcmItemForm.validateSection(r))return jQuery("html, body").animate({scrollTop:jQuery("#system-message-container").position().top},"slow"),!1;jQuery("#system-message-container").html(""),jQuery("#item-form .toggle-editor a").each(function(e){this.click()}),r.length&&r.each(function(){"file"==jQuery(this).attr("type")?null!=jQuery(this)[0].files[0]&&t.append(jQuery(this).attr("name"),jQuery(this)[0].files[0]):"checkbox"==jQuery(this).attr("type")?1==jQuery(this).prop("checked")?jQuery(this).val(1):jQuery(this).val(0):null!=jQuery(this).val()&&t.append(jQuery(this).attr("name"),jQuery(this).val())}),jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!0),tjUcmItemForm.getUcmParentRecordId(1,function(){t.delete("task"),t.delete("option"),t.delete("view"),t.delete("layout");var r=jQuery("#item-form").find("input[name='jform[client]']").val(),a=jQuery("#item-form").find("input[name='jform[id]']").val();t.append(Joomla.getOptions("csrf.token"),1),t.append("client",r),t.append("recordid",a),t.append("tjUcmFormSection",jQuery("a[href='"+e+"']").html()),com_tjucm.Services.Item.saveFormData(t,tjUcmItemForm.afterDataSave)})},validateSection:function(e){var t,r,a,i,n,o=!0,m=[];for(i=0,n=e.length;i0){for(t=Joomla.JText._("JLIB_FORM_FIELD_INVALID"),r={error:[]},i=m.length-1;i>=0;i--)(a=jQuery(m[i]).data("label"))&&r.error.push(t+a.text().replace("*",""));Joomla.renderMessages(r)}return o},setVisibilityOfNavigationButtons:function(){var e=jQuery("#tjucm_myTabTabs").find("li.active");jQuery(e).length&&(jQuery(e).next("li").length?jQuery("#next_button").attr("disabled",!1):jQuery("#next_button").attr("disabled",!0),jQuery(e).prev("li").length?jQuery("#previous_button").attr("disabled",!1):jQuery("#previous_button").attr("disabled",!0))}};function steppedFormSave(e,t,r){window.onbeforeunload=null,jQuery("#item-form .toggle-editor a").each(function(e){this.click()});var a=jQuery("#"+e),i=!1;if(jQuery("#form_status").val(t),"save"==t){if(!document.formvalidator.isValid("#item-form"))return jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!1),jQuery("html, body").animate({scrollTop:jQuery("#system-message-container").position().top},"slow"),!1;if(!confirm(Joomla.JText._("COM_TJUCM_ITEMFORM_SUBMIT_ALERT")))return jQuery(".form-actions button[type='button'], .form-actions input[type='button']").attr("disabled",!1),jQuery("html, body").animate({scrollTop:jQuery("#system-message-container").position().top},"slow"),!1;jQuery("#item-form").removeClass("dirty")}return a&&jQuery(a).ajaxSubmit({datatype:"JSON",async:!1,success:function(e){var a=JSON.parse(e);if(null!==a.messages&&null!==a.messages.error&&(jQuery.each(a.messages.error,function(e,t){Joomla.renderMessages({error:[t]})}),jQuery("html, body").animate({scrollTop:jQuery("#system-message-container").position().top},"slow")),null!==a.message&&""!=a.message&&(Joomla.renderMessages({info:[a.message]}),jQuery("html, body").animate({scrollTop:jQuery("#system-message-container").position().top},"slow")),null!==a.data){jQuery("#recordId").val(a.data.id),"save"==t?(jQuery("#tjUcmSectionFinalSave").attr("disabled","disabled"),Joomla.renderMessages({success:[Joomla.JText._("COM_TJUCM_MSG_ON_SAVED_FORM")]}),jQuery("html, body").animate({scrollTop:jQuery("#system-message-container").offset().top-40},"slow")):(i=!0,"1"===r&&(jQuery("#draft_msg").show(),setTimeout(function(){jQuery("#draft_msg").hide()},5e3)));var n=window.location.href.split("#")[0],o=-1===n.indexOf("?")?"?":"&",m="id="+a.data.id;jQuery.each(a.data.childContentIds,function(e,t){jQuery("input[name='"+t.elementName+"']").val(t.content_id)}),tjucmRelatedFieldUpdatedOptions=a.data.relatedFieldOptions,jQuery.each(a.data.relatedFieldOptions,function(e,t){jQuery("#"+t.elementId).html(""),jQuery.each(t.options,function(e,r){var a="";"1"==r.selected&&(a=' selected="selected" '),jQuery("#"+t.elementId).append('")}),jQuery("#"+t.elementId).trigger("liszt:updated")}),n.indexOf(m)>=0||(n+=o+m),history.pushState(null,null,n)}jQuery("#tjUcmSectionDraftSave").attr("disabled",!1),jQuery("#tjUcmSectionFinalSave").attr("disabled",!1),jQuery("#item-form .toggle-editor a").each(function(e){this.click()})}}),i}function itemformactions(e,t){var r=jQuery("ul#tjucm_myTabTabs").find("li.active a");null==jQuery(r).next("li")?jQuery("#previous_button").attr("disabled",!0):jQuery("#previous_button").attr("disabled",!1),null==jQuery(r).prev("li")?jQuery("#next_button").attr("disabled",!0):jQuery("#next_button").attr("disabled",!1),next?jQuery("#tjucm_myTabTabs > .active").next("li").find("a").trigger("click"):jQuery("#tjucm_myTabTabs > .active").next("li").prev("a").trigger("click");var a=jQuery("ul#"+getTabId).find("li.active").next("li").children("a").attr("href"),i=jQuery("ul#"+getTabId).find("li.active").prev("li").children("a").attr("href");null==a?jQuery("#next_button").attr("disabled",!0):jQuery("#next_button").attr("disabled",!1),null==i?jQuery("#previous_button").attr("disabled",!0):jQuery("#previous_button").attr("disabled",!1),steppedFormSave("item-form","draft",1),"next"==t&&jQuery("#"+getTabId+" > .active").next("li").find("a").trigger("click"),"prev"==t&&jQuery("#"+getTabId+" > .active").prev("li").find("a").trigger("click")} diff --git a/src/components/com_tjucm/site/controllers/item.php b/src/components/com_tjucm/site/controllers/item.php index ab40ac17..82ae26cd 100644 --- a/src/components/com_tjucm/site/controllers/item.php +++ b/src/components/com_tjucm/site/controllers/item.php @@ -93,7 +93,6 @@ public function edit() // Get the model. $model = $this->getModel('Item', 'TjucmModel'); - // Check out the item if ($editId) @@ -133,12 +132,10 @@ public function publish() $tjUcmFrontendHelper = new TjucmHelpersTjucm; // Checking if the user can remove object - $user = JFactory::getUser(); - $canEdit = $user->authorise('core.type.edititem', 'com_tjucm.type.edititem' . $this->ucmTypeId); - $canChange = $user->authorise('core.type.edititemstate', 'com_tjucm.type.' . $this->ucmTypeId); + $canEdit = $this->canEdit($this->ucmTypeId); + $canEditState = $this->canEditState($this->ucmTypeId); - - if ($canEdit || $canChange) + if ($canEdit || $canEditState) { $model = $this->getModel('Item', 'TjucmModel'); @@ -193,8 +190,7 @@ public function remove() $app = JFactory::getApplication(); // Checking if the user can remove object - $user = JFactory::getUser(); - $canDelete = $user->authorise('core.type.deleteitem', 'com_tjucm.type.' . $this->ucmTypeId); + $canDelete = $this->canDelete($this->ucmTypeId); if ($canDelete) { diff --git a/src/components/com_tjucm/site/controllers/itemform.json.php b/src/components/com_tjucm/site/controllers/itemform.json.php index 74462925..9ca345f0 100644 --- a/src/components/com_tjucm/site/controllers/itemform.json.php +++ b/src/components/com_tjucm/site/controllers/itemform.json.php @@ -123,10 +123,22 @@ public function save($key = null, $urlVar = null) $app->close(); } + $isNew = (empty($data['id'])) ? 1 : 0; + + // Plugin trigger on before item save + JPluginHelper::importPlugin('actionlog'); + $dispatcher = JDispatcher::getInstance(); + $dispatcher->trigger('tjUcmOnBeforeSaveItem', array($data, $isNew)); + if ($model->save($data)) { $result['id'] = $model->getState($model->getName() . '.id'); + // Plugin trigger on after item save + JPluginHelper::importPlugin('actionlog'); + $dispatcher = JDispatcher::getInstance(); + $dispatcher->trigger('tjUcmOnafterSaveItem', array($data, $isNew)); + echo new JResponseJson($result, Text::_('COM_TJUCM_ITEM_SAVED_SUCCESSFULLY')); $app->close(); } @@ -202,9 +214,19 @@ public function saveFieldData() $fieldData['client'] = $client; $fieldData['created_by'] = $table->created_by; + // Plugin trigger on before item date save + JPluginHelper::importPlugin('actionlog'); + $dispatcher = JDispatcher::getInstance(); + $dispatcher->trigger('tjUcmOnBeforeSaveItemData', array($recordId, $client, $data)); + // If data is valid then save the data into DB $response = $model->saveFieldsData($fieldData); + // Plugin trigger on after item data save + JPluginHelper::importPlugin('actionlog'); + $dispatcher = JDispatcher::getInstance(); + $dispatcher->trigger('tjUcmOnAfterSaveItemData', array($recordId, $client, $data)); + echo new JResponseJson($response); $app->close(); } @@ -313,9 +335,19 @@ public function saveFormData() $formData['client'] = $client; $formData['created_by'] = $table->created_by; + // Plugin trigger on before item date save + JPluginHelper::importPlugin('actionlog'); + $dispatcher = JDispatcher::getInstance(); + $dispatcher->trigger('tjUcmOnBeforeSaveItemData', array($recordId, $client, $data)); + // If data is valid then save the data into DB $response = $model->saveFieldsData($formData); + // Plugin trigger on before item date save + JPluginHelper::importPlugin('actionlog'); + $dispatcher = JDispatcher::getInstance(); + $dispatcher->trigger('tjUcmOnAfterSaveItemData', array($recordId, $client, $data)); + $msg = null; if ($response && empty($section)) diff --git a/src/components/com_tjucm/site/controllers/items.php b/src/components/com_tjucm/site/controllers/items.php index a974a459..3e905acb 100644 --- a/src/components/com_tjucm/site/controllers/items.php +++ b/src/components/com_tjucm/site/controllers/items.php @@ -170,32 +170,49 @@ public function importCsv() if (isset($fieldsArray[$fieldName]->options) && !empty($fieldsArray[$fieldName]->options)) { $fieldParams = new Registry($fieldsArray[$fieldName]->params); + $fieldOptions = array_column($fieldsArray[$fieldName]->options, 'options'); // If there are multiple values for a field then we need to send those as array if (strpos($value, '||') !== false && $fieldParams->get('multiple')) { $optionValue = array_map('trim', explode("||", $value)); $multiSelectValues = array(); + $otherOptionsValues = array(); - foreach ($fieldsArray[$fieldName]->options as $option) + foreach ($optionValue as $option) { - if (in_array($option->options, $optionValue)) + if (in_array($option, $fieldOptions)) { - $multiSelectValues[] = $option->value; + $multiSelectValues[] = $option; } + else + { + if ($fieldParams->get('other')) + { + $otherOptionsValues[] = $option; + } + } + } + + if (!empty($otherOptionsValues)) + { + $multiSelectValues[] = 'tjlistothervalue'; + $multiSelectValues[] = implode(',', $otherOptionsValues); } $itemData[$fieldName] = $multiSelectValues; } else { - foreach ($fieldsArray[$fieldName]->options as $option) + if (in_array($value, $fieldOptions)) + { + $itemData[$fieldName] = $value; + } + else { - if ($option->options == $value) + if ($fieldParams->get('other')) { - $itemData[$fieldName] = $option->value; - - break; + $itemData[$fieldName] = array('tjlistothervalue', $value); } } } diff --git a/src/components/com_tjucm/site/controllers/type.php b/src/components/com_tjucm/site/controllers/type.php index 6e266dfe..34c27107 100644 --- a/src/components/com_tjucm/site/controllers/type.php +++ b/src/components/com_tjucm/site/controllers/type.php @@ -64,17 +64,18 @@ public function getCompatableUcmType() $typeModel = BaseDatabaseModel::getInstance('Type', 'TjucmModel'); $validUcmType = array(); - $validUcmType[0]['value'] = ""; - $validUcmType[0]['text'] = Text::_('COM_TJUCM_SELECT_UCM_TYPE_DESC'); foreach ($ucmTypes as $key => $type) { - $result = $typeModel->getCompatableUcmType($client, $type->unique_identifier); - - if ($result) + if ($type->unique_identifier != $client) { - $validUcmType[$key]['value'] = $type->unique_identifier; - $validUcmType[$key]['text'] = $type->title; + $result = $typeModel->getCompatableUcmType($client, $type->unique_identifier); + + if ($result) + { + $validUcmType[$key]['value'] = $type->unique_identifier; + $validUcmType[$key]['text'] = $type->title; + } } } diff --git a/src/components/com_tjucm/site/includes/access.php b/src/components/com_tjucm/site/includes/access.php new file mode 100644 index 00000000..7f698413 --- /dev/null +++ b/src/components/com_tjucm/site/includes/access.php @@ -0,0 +1,266 @@ + + * @copyright Copyright (C) 2009 - 2020 Techjoomla. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +defined('_JEXEC') or die(); + +use Joomla\CMS\Factory; +use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; +use Joomla\CMS\Table\Table; +use Joomla\String\StringHelper; + +require_once JPATH_SITE . '/components/com_tjucm/includes/defines.php'; + +/** + * Tjucm factory class. + * + * This class perform the helpful operation required to Tjucm package + * + * @since __DEPLOY_VERSION__ + */ +class TjucmAccess +{ + public static function canCreate($ucmTypeId) + { + if (TjucmAccess::hasCluster($ucmTypeId)) + { + // Get com_subusers component status + $subUserExist = ComponentHelper::getComponent('com_subusers', true)->enabled; + + // Check user have permission to edit record of assigned cluster + if ($subUserExist) + { + JLoader::import("/components/com_subusers/includes/rbacl", JPATH_ADMINISTRATOR); + + return RBACL::check(JFactory::getUser()->id, 'com_cluster', 'core.createitem.' . $ucmTypeId); + } + } + else + { + return JFactory::getUser()->authorise('core.type.createitem', 'com_tjucm.type.' . $ucmTypeId); + } + } + + public static function canImport($ucmTypeId) + { + if (TjucmAccess::hasCluster($ucmTypeId)) + { + // Get com_subusers component status + $subUserExist = ComponentHelper::getComponent('com_subusers', true)->enabled; + + // Check user have permission to edit record of assigned cluster + if ($subUserExist) + { + JLoader::import("/components/com_subusers/includes/rbacl", JPATH_ADMINISTRATOR); + + return RBACL::check(JFactory::getUser()->id, 'com_cluster', 'core.importitem.' . $ucmTypeId) && RBACL::check(JFactory::getUser()->id, 'com_cluster', 'core.createtitem.' . $ucmTypeId); + } + } + else + { + return JFactory::getUser()->authorise('core.type.importitem', 'com_tjucm.type.' . $ucmTypeId); + } + } + + public static function canView($ucmTypeId, $contentId) + { + JLoader::import('components.com_tjucm.tables.item', JPATH_ADMINISTRATOR); + $itemTable = JTable::getInstance('Item', 'TjucmTable', array('dbo', JFactory::getDbo())); + $itemTable->load($contentId); + + if (JFactory::getUser()->id == $itemTable->created_by) + { + return true; + } + + JLoader::import("/components/com_subusers/includes/rbacl", JPATH_ADMINISTRATOR); + + if (TjucmAccess::hasCluster($ucmTypeId)) + { + if (RBACL::check(JFactory::getUser()->id, 'com_cluster', 'core.viewallitem.' . $ucmTypeId)) + { + return true; + } + + // Get com_subusers component status + $subUserExist = ComponentHelper::getComponent('com_subusers', true)->enabled; + + // Check user have permission to edit record of assigned cluster + if ($subUserExist) + { + return RBACL::check(JFactory::getUser()->id, 'com_cluster', 'core.viewitem.' . $ucmTypeId, $itemTable->cluster_id); + } + } + else + { + return JFactory::getUser()->authorise('core.type.viewitem', 'com_tjucm.type.' . $ucmTypeId); + } + } + + public static function canEdit($ucmTypeId, $contentId) + { + if (TjucmAccess::hasCluster($ucmTypeId)) + { + JLoader::import("/components/com_subusers/includes/rbacl", JPATH_ADMINISTRATOR); + + if (RBACL::check(JFactory::getUser()->id, 'com_cluster', 'core.editallitem.' . $ucmTypeId)) + { + return true; + } + + // Get com_subusers component status + $subUserExist = ComponentHelper::getComponent('com_subusers', true)->enabled; + + // Check user have permission to edit record of assigned cluster + if ($subUserExist) + { + JLoader::import('components.com_tjucm.tables.item', JPATH_ADMINISTRATOR); + $itemTable = JTable::getInstance('Item', 'TjucmTable', array('dbo', JFactory::getDbo())); + $itemTable->load($contentId); + + return RBACL::check(JFactory::getUser()->id, 'com_cluster', 'core.edititem.' . $ucmTypeId, $itemTable->cluster_id); + } + } + else + { + return JFactory::getUser()->authorise('core.type.edititem', 'com_tjucm.type.' . $ucmTypeId); + } + } + + public static function canEditState($ucmTypeId, $contentId) + { + if (TjucmAccess::hasCluster($ucmTypeId)) + { + JLoader::import("components.com_subusers.includes.rbacl", JPATH_ADMINISTRATOR); + + if (RBACL::check(JFactory::getUser()->id, 'com_cluster', 'core.editallitemstate.' . $ucmTypeId)) + { + return true; + } + + // Get com_subusers component status + $subUserExist = ComponentHelper::getComponent('com_subusers', true)->enabled; + + // Check user have permission to edit record of assigned cluster + if ($subUserExist) + { + JLoader::import('components.com_tjucm.tables.item', JPATH_ADMINISTRATOR); + $itemTable = JTable::getInstance('Item', 'TjucmTable', array('dbo', JFactory::getDbo())); + $itemTable->load($contentId); + + return RBACL::check(JFactory::getUser()->id, 'com_cluster', 'core.edititemstate.' . $ucmTypeId, $itemTable->cluster_id); + } + } + else + { + return JFactory::getUser()->authorise('core.type.edititemstate', 'com_tjucm.type.' . $ucmTypeId); + } + } + + public static function canEditOwn($ucmTypeId, $contentId) + { + if (TjucmAccess::hasCluster($ucmTypeId)) + { + // Get com_subusers component status + $subUserExist = ComponentHelper::getComponent('com_subusers', true)->enabled; + + // Check user have permission to edit record of assigned cluster + if ($subUserExist) + { + JLoader::import("/components/com_subusers/includes/rbacl", JPATH_ADMINISTRATOR); + JLoader::import('components.com_tjucm.tables.item', JPATH_ADMINISTRATOR); + $itemTable = JTable::getInstance('Item', 'TjucmTable', array('dbo', JFactory::getDbo())); + $itemTable->load($contentId); + + return RBACL::check(JFactory::getUser()->id, 'com_cluster', 'core.editownitem.' . $ucmTypeId, $itemTable->cluster_id); + } + } + else + { + return JFactory::getUser()->authorise('core.type.editownitem', 'com_tjucm.type.' . $ucmTypeId); + } + } + + public static function canDelete($ucmTypeId, $contentId) + { + if (TjucmAccess::hasCluster($ucmTypeId)) + { + JLoader::import("/components/com_subusers/includes/rbacl", JPATH_ADMINISTRATOR); + + if (RBACL::check(JFactory::getUser()->id, 'com_cluster', 'core.deleteallitem.' . $ucmTypeId)) + { + return true; + } + + // Get com_subusers component status + $subUserExist = ComponentHelper::getComponent('com_subusers', true)->enabled; + + // Check user have permission to edit record of assigned cluster + if ($subUserExist) + { + JLoader::import('components.com_tjucm.tables.item', JPATH_ADMINISTRATOR); + $itemTable = JTable::getInstance('Item', 'TjucmTable', array('dbo', JFactory::getDbo())); + $itemTable->load($contentId); + + return RBACL::check(JFactory::getUser()->id, 'com_cluster', 'core.deleteitem.' . $ucmTypeId, $itemTable->cluster_id); + } + } + else + { + return JFactory::getUser()->authorise('core.type.deleteitem', 'com_tjucm.type.' . $ucmTypeId); + } + } + + public static function canDeleteOwn($ucmTypeId, $contentId) + { + if (TjucmAccess::hasCluster($ucmTypeId)) + { + // Get com_subusers component status + $subUserExist = ComponentHelper::getComponent('com_subusers', true)->enabled; + + // Check user have permission to edit record of assigned cluster + if ($subUserExist) + { + JLoader::import("/components/com_subusers/includes/rbacl", JPATH_ADMINISTRATOR); + JLoader::import('components.com_tjucm.tables.item', JPATH_ADMINISTRATOR); + $itemTable = JTable::getInstance('Item', 'TjucmTable', array('dbo', JFactory::getDbo())); + $itemTable->load($contentId); + + return RBACL::check(JFactory::getUser()->id, 'com_cluster', 'core.deleteownitem.' . $ucmTypeId, $itemTable->cluster_id); + } + } + else + { + return JFactory::getUser()->authorise('core.type.deleteownitem', 'com_tjucm.type.' . $ucmTypeId); + } + } + + public static function hasCluster($ucmTypeId) + { + if (ComponentHelper::getComponent('com_cluster', true)->enabled) + { + JLoader::import('components.com_tjucm.tables.type', JPATH_ADMINISTRATOR); + $typeTable = JTable::getInstance('Type', 'TjucmTable', array('dbo', JFactory::getDbo())); + $typeTable->load($ucmTypeId); + + JLoader::import('components.com_tjfields.tables.field', JPATH_ADMINISTRATOR); + $fieldTable = JTable::getInstance('Field', 'TjfieldsTable', array('dbo', JFactory::getDbo())); + $fieldTable->load(array('client' => $typeTable->unique_identifier, 'type' => 'cluster', 'state' => 1)); + + if ($fieldTable->id) + { + return true; + } + } + + return false; + } +} diff --git a/src/components/com_tjucm/site/layouts/list/list.php b/src/components/com_tjucm/site/layouts/list/list.php index 6ff9d6a7..56fd4708 100644 --- a/src/components/com_tjucm/site/layouts/list/list.php +++ b/src/components/com_tjucm/site/layouts/list/list.php @@ -43,6 +43,10 @@ JLoader::import('components.com_tjfields.helpers.tjfields', JPATH_SITE); $TjfieldsHelper = new TjfieldsHelper; +// Load itemForm model +JLoader::import('components.com_tjucm.models.itemform', JPATH_SITE); +$tjucmItemFormModel = JModelLegacy::getInstance('ItemForm', 'TjucmModel'); + // Get JLayout data $item = $displayData['itemsData']; $created_by = $displayData['created_by']; @@ -55,11 +59,11 @@ $appendUrl = ''; $csrf = "&" . Session::getFormToken() . '=1'; -$canEditOwn = $user->authorise('core.type.editownitem', 'com_tjucm.type.' . $ucmTypeId); -$canDeleteOwn = $user->authorise('core.type.deleteownitem', 'com_tjucm.type.' . $ucmTypeId); -$canChange = $user->authorise('core.type.edititemstate', 'com_tjucm.type.' . $ucmTypeId); -$canEdit = $user->authorise('core.type.edititem', 'com_tjucm.type.' . $ucmTypeId); -$canDelete = $user->authorise('core.type.deleteitem', 'com_tjucm.type.' . $ucmTypeId); +$canEditOwn = TjucmAccess::canEditOwn($ucmTypeId, $item->id); +$canDeleteOwn = TjucmAccess::canDeleteOwn($ucmTypeId, $item->id); +$canEditState = TjucmAccess::canEditState($ucmTypeId, $item->id); +$canEdit = TjucmAccess::canEdit($ucmTypeId, $item->id); +$canDelete = TjucmAccess::canDelete($ucmTypeId, $item->id); if (!empty($created_by)) { @@ -94,16 +98,17 @@ ?>
- + + id); ?> state)) { - $class = ($canChange) ? 'active' : 'disabled'; ?> + $class = ($canEditState) ? 'active' : 'disabled'; ?> id . '&state=' . (($item->state + 1) % 2) . $appendUrl . $csrf : '#'; ?>"> state == 1) @@ -157,47 +162,115 @@ { $field = $formObject->getField($tjFieldsFieldTable->name); $field->setValue($fieldValue); - $layoutToUse = ( - array_key_exists( - ucfirst($tjFieldsFieldTable->type), $fieldLayout - ) - ) ? $fieldLayout[ucfirst($tjFieldsFieldTable->type)] : 'field'; - $layout = new JLayoutFile($layoutToUse, JPATH_ROOT . '/components/com_tjfields/layouts/fields'); - $output = $layout->render(array('fieldXml' => $fieldXml, 'field' => $field)); - echo $output; + + if ($field->type == 'Ucmsubform' && $fieldValue) + { + $ucmSubFormData = json_decode($tjucmItemFormModel->getUcmSubFormFieldDataJson($item->id, $field)); + $field->setValue($ucmSubFormData); + ?> +
+
label; ?>:
+
+ getFieldData($field->getAttribute('name')); + + $ucmSubFormFieldParams = json_decode($fieldData->params); + $ucmSubFormFormSource = explode('/', $ucmSubFormFieldParams->formsource); + $ucmSubFormClient = $ucmSubFormFormSource[1] . '.' . str_replace('form_extra.xml', '', $ucmSubFormFormSource[4]); + $view = explode('.', $ucmSubFormClient); + $ucmSubFormData = (array) $ucmSubFormData; + + if (!empty($ucmSubFormData)) + { + $count = 0; + + foreach ($ucmSubFormData as $subFormData) + { + $count++; + $contentIdFieldname = str_replace('.', '_', $ucmSubFormClient) . '_contentid'; + + $ucmSubformFormObject = $tjucmItemModel->getFormExtra( + array( + "clientComponent" => 'com_tjucm', + "client" => $ucmSubFormClient, + "view" => $view[1], + "layout" => 'default', + "content_id" => $subFormData->$contentIdFieldname) + ); + + $ucmSubFormFormXml = simplexml_load_file($field->formsource); + + $ucmSubFormCount = 0; + + foreach ($ucmSubFormFormXml as $ucmSubFormXmlFieldSet) + { + $ucmSubFormXmlFieldSets[$ucmSubFormCount] = $ucmSubFormXmlFieldSet; + $ucmSubFormCount++; + } + + $ucmSubFormRecordData = $tjucmItemModel->getData($subFormData->$contentIdFieldname); + + // Call the JLayout recursively to render fields of ucmsubform + $layout = new JLayoutFile('fields', JPATH_ROOT . '/components/com_tjucm/layouts/detail'); + echo $layout->render(array('xmlFormObject' => $ucmSubFormXmlFieldSets, 'formObject' => $ucmSubformFormObject, 'itemData' => $ucmSubFormRecordData, 'isSubForm' => 1)); + + if (count($ucmSubFormData) > $count) + { + echo "
"; + } + } + } + ?> +
+
+ type), $fieldLayout + ) + ) ? $fieldLayout[ucfirst($tjFieldsFieldTable->type)] : 'field'; + $layout = new JLayoutFile($layoutToUse, JPATH_ROOT . '/components/com_tjfields/layouts/fields'); + $output = $layout->render(array('fieldXml' => $fieldXml, 'field' => $field)); + echo $output; + } } ?> + +
+ - - + | - | - - | - - - - - id . $appendUrl . $csrf; ?>" + class="delete-button" type="button" + title=""> | + + + +
diff --git a/src/components/com_tjucm/site/models/item.php b/src/components/com_tjucm/site/models/item.php index 8d7c199f..4715d402 100644 --- a/src/components/com_tjucm/site/models/item.php +++ b/src/components/com_tjucm/site/models/item.php @@ -44,7 +44,6 @@ class TjucmModelItem extends JModelAdmin protected function populateState() { $app = JFactory::getApplication('com_tjucm'); - $user = JFactory::getUser(); // Load state from the request. $id = $app->input->getInt('id'); @@ -83,9 +82,7 @@ protected function populateState() $this->setState('ucmType.id', $ucmId); // Check published state - if ((!$user->authorise('core.type.edititem', 'com_tjucm.type.' . $ucmId)) - && (!$user->authorise('core.type.editownitem', 'com_tjucm.type.' . $ucmId)) - && (!$user->authorise('core.type.edititemstate', 'com_tjucm.type.' . $ucmId))) + if ((!TjucmAccess::canEdit($ucmId, $id)) && (!TjucmAccess::canEditOwn($ucmId, $id)) && (!TjucmAccess::canEditState($ucmId, $id))) { $this->setState('filter.published', 1); $this->setState('fileter.archived', 2); @@ -173,8 +170,6 @@ public function getItem($pk = null) */ public function &getData($id = null) { - $user = JFactory::getUser(); - $this->item = false; if (empty($id)) @@ -184,7 +179,7 @@ public function &getData($id = null) // Get UCM type id (Get if user is autorised to edit the items for this UCM type) $ucmTypeId = $this->getState('ucmType.id'); - $canView = $user->authorise('core.type.viewitem', 'com_tjucm.type.' . $ucmTypeId); + $canView = TjucmAccess::canView($ucmTypeId, $id); // Get a level row instance. $table = $this->getTable(); @@ -214,7 +209,7 @@ public function &getData($id = null) if (!empty($this->item->id)) { - if ($canView || ($this->item->created_by == $user->id)) + if ($canView || ($this->item->created_by == JFactory::getUser()->id)) { $this->item->params->set('access-view', true); } @@ -274,8 +269,7 @@ public function delete(&$id) $app = JFactory::getApplication('com_tjucm'); $ucmTypeId = $this->getState('ucmType.id'); - $user = JFactory::getUser(); - $canDelete = $user->authorise('core.type.deleteitem', 'com_tjucm.type.' . $ucmTypeId); + $canDelete = TjucmAccess::canDelete($ucmTypeId, $id); if ($canDelete) { @@ -290,18 +284,4 @@ public function delete(&$id) return false; } } - - /** - * Method to check if a user has permissions to view ucm items of given type - * - * @param int $typeId Type Id - * - * @return boolean - */ - public function canView($typeId) - { - $user = JFactory::getUser(); - - return $user->authorise('core.type.viewitem', 'com_tjucm.type.' . $typeId); - } } diff --git a/src/components/com_tjucm/site/models/itemform.php b/src/components/com_tjucm/site/models/itemform.php index 559c968f..c754501a 100644 --- a/src/components/com_tjucm/site/models/itemform.php +++ b/src/components/com_tjucm/site/models/itemform.php @@ -23,6 +23,8 @@ use Joomla\Registry\Registry; use Joomla\CMS\Language\Text; +JLoader::register('TjucmAccess', JPATH_SITE . '/components/com_tjucm/includes/access.php'); + /** * Tjucm model. * @@ -103,9 +105,7 @@ protected function populateState() $this->setState('ucmType.id', $ucmId); // Check published state - if ((!$user->authorise('core.type.edititem', 'com_tjucm.type.' . $ucmId)) - && (!$user->authorise('core.type.editownitem', 'com_tjucm.type.' . $ucmId)) - && (!$user->authorise('core.type.edititemstate', 'com_tjucm.type.' . $ucmId))) + if ((!TjucmAccess::canEdit($ucmId, $id)) && (!TjucmAccess::canEditOwn($ucmId, $id)) && (!TjucmAccess::canEditState($ucmId, $id))) { $this->setState('filter.published', 1); $this->setState('fileter.archived', 2); @@ -145,9 +145,9 @@ public function &getData($id = null) // Get UCM type id (Get if user is autorised to edit the items for this UCM type) $ucmTypeId = $this->getState('ucmType.id'); - $canEdit = $user->authorise('core.type.edititem', 'com_tjucm.type.' . $ucmTypeId); - $canEditOwn = $user->authorise('core.type.editownitem', 'com_tjucm.type.' . $ucmTypeId); - $canCreate = $user->authorise('core.type.createitem', 'com_tjucm.type.' . $ucmTypeId); + $canEdit = TjucmAccess::canEdit($ucmTypeId, $id); + $canEditOwn = TjucmAccess::canEditOwn($ucmTypeId, $id); + $canCreate = TjucmAccess::canCreate($ucmTypeId); // Get a level row instance. $table = $this->getTable(); @@ -535,6 +535,7 @@ public function save($data) } $ucmTypeParams = new Registry($tjUcmTypeTable->params); + // Check if UCM type is subform $isSubform = $ucmTypeParams->get('is_subform'); @@ -567,7 +568,7 @@ public function save($data) $allowedCount = $ucmTypeParams->get('allowed_count', 0, 'INT'); // Check if the user is allowed to add record for given UCM type - $canAdd = $user->authorise('core.type.createitem', 'com_tjucm.type.' . $data['type_id']); + $canAdd = TjucmAccess::canCreate($data['type_id']); if (!$canAdd) { @@ -592,8 +593,8 @@ public function save($data) else { // Check if the user can edit this record - $canEdit = $user->authorise('core.type.edititem', 'com_tjucm.type.' . $data['type_id']); - $canEditOwn = $user->authorise('core.type.editownitem', 'com_tjucm.type.' . $data['type_id']); + $canEdit = TjucmAccess::canEdit($data['type_id'], $data['id']); + $canEditOwn = TjucmAccess::canEditOwn($data['type_id'], $data['id']); $itemTable = $this->getTable(); $itemTable->load(array('id' => $data['id'])); @@ -690,8 +691,8 @@ public function delete(&$contentId) $user = JFactory::getUser(); $table = $this->getTable(); $table->load($contentId); - $canDelete = $user->authorise('core.type.deleteitem', 'com_tjucm.type.' . $table->type_id); - $canDeleteown = $user->authorise('core.type.deleteownitem', 'com_tjucm.type.' . $table->type_id); + $canDelete = TjucmAccess::canDelete($table->type_id, $contentId); + $canDeleteown = TjucmAccess::canDeleteOwn($table->type_id, $contentId); $deleteOwn = false; @@ -726,9 +727,19 @@ public function delete(&$contentId) { $table->load($subFormContentId); + // Plugin trigger on before item delete + JPluginHelper::importPlugin('actionlog'); + $dispatcher = JDispatcher::getInstance(); + $dispatcher->trigger('tjUcmOnBeforeDeleteItem', array($subFormContentId, $table->client)); + if ($table->delete($subFormContentId) === true) { $this->deleteExtraFieldsData($subFormContentId, $table->client); + + // Plugin trigger on after item delete + JPluginHelper::importPlugin('actionlog'); + $dispatcher = JDispatcher::getInstance(); + $dispatcher->trigger('tjUcmOnAfterDeleteItem', array($subFormContentId, $table->client)); } } } @@ -736,10 +747,20 @@ public function delete(&$contentId) // Delete parent record $table->load($id); + // Plugin trigger on before item delete + JPluginHelper::importPlugin('actionlog'); + $dispatcher = JDispatcher::getInstance(); + $dispatcher->trigger('tjUcmOnBeforeDeleteItem', array($id, $table->client)); + if ($table->delete($id) === true) { $this->deleteExtraFieldsData($id, $table->client); + // Plugin trigger on after item delete + JPluginHelper::importPlugin('actionlog'); + $dispatcher = JDispatcher::getInstance(); + $dispatcher->trigger('tjUcmOnAfterDeleteItem', array($id, $table->client)); + return $id; } else @@ -888,6 +909,16 @@ public function getUcmSubFormFieldDataJson($parentRecordId, $efd) $subFormData->$ucmSubformContentIdFieldName = $contentId; $concat = $efd->name . $key; + + // Check if any field has value for the subform entry and if there is no value in subform then dont show it + $subFormDataArray = (array) $subFormData; + unset($subFormDataArray[$ucmSubformContentIdFieldName]); + + if (empty($subFormDataArray)) + { + continue; + } + $ucmSubFormFieldData->$concat = $subFormData; } diff --git a/src/components/com_tjucm/site/models/items.php b/src/components/com_tjucm/site/models/items.php index 7a48084a..03b24d34 100644 --- a/src/components/com_tjucm/site/models/items.php +++ b/src/components/com_tjucm/site/models/items.php @@ -145,13 +145,6 @@ protected function populateState($ordering = "a.id", $direction = "DESC") $this->setState("ucmType.id", $typeId); $createdBy = $app->input->get('created_by', "", "INT"); - $canView = $user->authorise('core.type.viewitem', 'com_tjucm.type.' . $typeId); - - if (!$canView) - { - $createdBy = $user->id; - } - $this->setState("created_by", $createdBy); if ($this->getUserStateFromRequest($this->context . $ucmType . '.filter.order', 'filter_order', '', 'string')) @@ -164,6 +157,26 @@ protected function populateState($ordering = "a.id", $direction = "DESC") $direction = $this->getUserStateFromRequest($this->context . $ucmType . '.filter.order_Dir', 'filter_order_Dir', '', 'string'); } + $fromDate = $this->getUserStateFromRequest($this->context . '.fromDate', 'fromDate', '', 'STRING'); + $toDate = $this->getUserStateFromRequest($this->context . '.toDate', 'toDate', '', 'STRING'); + + if (!empty($fromDate) || !empty($toDate)) + { + $fromDate = empty($fromDate) ? JFactory::getDate('now -1 month')->toSql() : JFactory::getDate($fromDate)->toSql(); + $toDate = empty($toDate) ? JFactory::getDate('now')->toSql() : JFactory::getDate($toDate)->toSql(); + + // If from date is less than to date then swipe the dates + if ($fromDate > $toDate) + { + $tmpDate = $fromDate; + $fromDate = $toDate; + $toDate = $tmpDate; + } + + $this->setState($ucmType . ".filter.fromDate", $fromDate); + $this->setState($ucmType . ".filter.toDate", $toDate); + } + // List state information. parent::populateState($ordering, $direction); } @@ -241,18 +254,21 @@ protected function getListQuery() if ($fieldTable->id) { - JFormHelper::addFieldPath(JPATH_ADMINISTRATOR . '/components/com_tjfields/models/fields/'); - $cluster = JFormHelper::loadFieldType('cluster', false); - $clusterList = $cluster->getOptionsExternally(); + JLoader::import("/components/com_cluster/includes/cluster", JPATH_ADMINISTRATOR); + $clustersModel = ClusterFactory::model('Clusters', array('ignore_request' => true)); + $clusters = $clustersModel->getItems(); $usersClusters = array(); - if (!empty($clusterList)) + if (!empty($clusters)) { - foreach ($clusterList as $clusterList) + foreach ($clusters as $clusterList) { - if (!empty($clusterList->value)) + if (!empty($clusterList->id)) { - $usersClusters[] = $clusterList->value; + if (TjucmAccess::canView($ucmTypeId, $clusterList->id)) + { + $usersClusters[] = $clusterList->id; + } } } } @@ -268,7 +284,7 @@ protected function getListQuery() } // Filter by published state - $published = $this->getState('filter.state'); + $published = $this->getState('filter.state', ''); if (is_numeric($published)) { @@ -276,7 +292,7 @@ protected function getListQuery() } elseif ($published === '') { - $query->where(($db->quoteName('(a.state) ') . ' IN (0, 1)')); + $query->where(($db->quoteName('a.state') . ' IN (0, 1)')); } // Filter by draft status @@ -286,6 +302,7 @@ protected function getListQuery() { $query->where($db->quoteName('a.draft') . ' = ' . $draft); } + // Search by content id $search = $this->getState($client . '.filter.search'); @@ -299,6 +316,14 @@ protected function getListQuery() } } + $fromDate = $this->getState($client . '.filter.fromDate'); + $toDate = $this->getState($client . '.filter.toDate'); + + if (!empty($fromDate) || !empty($toDate)) + { + $query->where('DATE(' . $db->quoteName('a.created_date') . ') ' . ' BETWEEN ' . $db->quote($fromDate) . ' AND ' . $db->quote($toDate)); + } + // Search on fields data $filteredItemIds = $this->filterContent($client); @@ -485,6 +510,8 @@ public function getFields() $fieldsModel = JModelLegacy::getInstance('Fields', 'TjfieldsModel', array('ignore_request' => true)); $fieldsModel->setState('filter.showonlist', 1); $fieldsModel->setState('filter.state', 1); + $fieldsModel->setState('list.ordering', 'ordering'); + $fieldsModel->setState('list.direction', 'ASC'); $client = $this->getState('ucm.client'); if (!empty($client)) @@ -511,28 +538,6 @@ public function getFields() */ public function getItems() { - $typeId = $this->getState('ucmType.id'); - $createdBy = $this->getState('created_by', ''); - - JLoader::import('components.com_tjucm.models.item', JPATH_SITE); - $itemModel = new TjucmModelItem; - $canView = $itemModel->canView($typeId); - $user = JFactory::getUser(); - - // If user is not allowed to view the records and if the created_by is not the logged in user then do not show the records - if (!$canView) - { - if (!empty($createdBy) && $createdBy == $user->id) - { - $canView = true; - } - } - - if (!$canView) - { - return false; - } - $items = parent::getItems(); $itemsArray = (array) $items; $contentIds = array_column($itemsArray, 'id'); diff --git a/src/components/com_tjucm/site/tjucm.php b/src/components/com_tjucm/site/tjucm.php index 4946512b..5d6cf2d3 100644 --- a/src/components/com_tjucm/site/tjucm.php +++ b/src/components/com_tjucm/site/tjucm.php @@ -34,6 +34,7 @@ TjucmHelpersTjucm::getLanguageConstantForJs(); // Initialise UCM +JLoader::register('TjucmAccess', JPATH_SITE . '/components/com_tjucm/includes/access.php'); JLoader::register('TJUCM', JPATH_SITE . '/components/com_tjucm/includes/tjucm.php'); TJUCM::init(); diff --git a/src/components/com_tjucm/site/views/item/tmpl/default.php b/src/components/com_tjucm/site/views/item/tmpl/default.php index 5d848ca9..a1e30e63 100644 --- a/src/components/com_tjucm/site/views/item/tmpl/default.php +++ b/src/components/com_tjucm/site/views/item/tmpl/default.php @@ -13,9 +13,21 @@ JText::script('COM_TJUCM_DELETE_MESSAGE'); $user = JFactory::getUser(); +$tjUcmFrontendHelper = new TjucmHelpersTjucm; if ($this->form_extra) { + if (isset($this->title)) + { + ?> + +
authorise('core.type.edititem', 'com_tjucm.type.' . $this->ucmTypeId)) || ($user->authorise('core.type.editownitem', 'com_tjucm.type.' . $this->ucmTypeId) && JFactory::getUser()->id == $this->item->created_by)) + if ((TjucmAccess::canEdit($this->ucmTypeId, $this->item->id)) || (TjucmAccess::canEditOwn($this->ucmTypeId, $this->item->id) && JFactory::getUser()->id == $this->item->created_by)) { $redirectURL = JRoute::_('index.php?option=com_tjucm&task=item.edit&id=' . $this->item->id . '&client=' . $this->client, false); ?> @@ -52,18 +64,22 @@ $deleteOwn = false; - if ($user->authorise('core.type.deleteownitem', 'com_tjucm.type.' . $this->ucmTypeId)) + if (TjucmAccess::canDeleteOwn($this->ucmTypeId, $this->item->id)) { $deleteOwn = (JFactory::getUser()->id == $this->item->created_by ? true : false); } - if ($user->authorise('core.type.deleteitem', 'com_tjucm.type.' . $this->ucmTypeId) || $deleteOwn) + if (TjucmAccess::canDelete($this->ucmTypeId, $this->item->id) || $deleteOwn) { $redirectURL = JRoute::_('index.php?option=com_tjucm&task=itemform.remove&id=' . $this->item->id . '&client=' . $this->client . "&" . JSession::getFormToken() . '=1', false); ?> client; + $itemId = $tjUcmFrontendHelper->getItemId($link); ?> +
- + \ No newline at end of file diff --git a/src/components/com_tjucm/site/views/item/view.html.php b/src/components/com_tjucm/site/views/item/view.html.php index e387c7ca..4921e994 100644 --- a/src/components/com_tjucm/site/views/item/view.html.php +++ b/src/components/com_tjucm/site/views/item/view.html.php @@ -41,6 +41,16 @@ public function display($tpl = null) { $app = JFactory::getApplication(); + if (!JFactory::getUser()->id) + { + $msg = JText::_('COM_TJUCM_LOGIN_MSG'); + + // Get current url. + $current = JUri::getInstance()->toString(); + $url = base64_encode($current); + JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_users&view=login&return=' . $url, false), $msg); + } + // Load tj-fields language file $lang = JFactory::getLanguage(); $lang->load('com_tjfields', JPATH_SITE); @@ -122,6 +132,7 @@ public function display($tpl = null) $typeTable = JTable::getInstance('Type', 'TjucmTable', array('dbo', JFactory::getDbo())); $typeTable->load(array('unique_identifier' => $this->client)); $typeParams = json_decode($typeTable->params); + $this->title = $typeTable->title; if (isset($typeParams->details_layout) && !empty($typeParams->details_layout)) { diff --git a/src/components/com_tjucm/site/views/itemform/tmpl/default.php b/src/components/com_tjucm/site/views/itemform/tmpl/default.php index 9b02b752..744fe6db 100644 --- a/src/components/com_tjucm/site/views/itemform/tmpl/default.php +++ b/src/components/com_tjucm/site/views/itemform/tmpl/default.php @@ -125,7 +125,8 @@

title); ?>

- + +
+ +
diff --git a/src/components/com_tjucm/site/views/itemform/view.html.php b/src/components/com_tjucm/site/views/itemform/view.html.php index 6f8e5301..b7eb4b54 100644 --- a/src/components/com_tjucm/site/views/itemform/view.html.php +++ b/src/components/com_tjucm/site/views/itemform/view.html.php @@ -103,6 +103,17 @@ public function display($tpl = null) $app = Factory::getApplication(); $input = $app->input; $user = Factory::getUser(); + + if (!$user->id) + { + $msg = JText::_('COM_TJUCM_LOGIN_MSG'); + + // Get current url. + $current = JUri::getInstance()->toString(); + $url = base64_encode($current); + JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_users&view=login&return=' . $url, false), $msg); + } + $this->state = $this->get('State'); $this->id = $input->getInt('id', $input->getInt('content_id', 0)); @@ -128,28 +139,6 @@ public function display($tpl = null) $clusterId = $this->item->cluster_id; } - // Get com_cluster component status - if (ComponentHelper::getComponent('com_cluster', true)->enabled) - { - // Get com_subusers component status - $subUserExist = ComponentHelper::getComponent('com_subusers', true)->enabled; - - // Check user have permission to edit record of assigned cluster - if ($subUserExist && !empty($clusterId) && !$user->authorise('core.manageall', 'com_cluster')) - { - JLoader::import("/components/com_subusers/includes/rbacl", JPATH_ADMINISTRATOR); - - // Check user has permission for mentioned cluster - if (!RBACL::authorise($user->id, 'com_cluster', 'core.manage', $clusterId)) - { - $app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error'); - $app->setHeader('status', 403, true); - - return; - } - } - } - // Get a copy record id $this->copyRecId = (int) $app->getUserState('com_tjucm.edit.itemform.data.copy_id', 0); @@ -232,6 +221,17 @@ public function display($tpl = null) $typeTable->load(array('unique_identifier' => $this->client)); $typeParams = json_decode($typeTable->params); + if ($this->item->id) + { + if (!TjucmAccess::canEdit($typeTable->id, $this->item->id) && !TjucmAccess::canEditOwn($typeTable->id, $this->item->id)) + { + $app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error'); + $app->setHeader('status', 403, true); + + return; + } + } + // Check if the UCM type is unpublished if ($typeTable->state == "0") { diff --git a/src/components/com_tjucm/site/views/items/tmpl/default.php b/src/components/com_tjucm/site/views/items/tmpl/default.php index be991251..e9b5df0a 100644 --- a/src/components/com_tjucm/site/views/items/tmpl/default.php +++ b/src/components/com_tjucm/site/views/items/tmpl/default.php @@ -54,11 +54,11 @@ jQuery(window).load(function() { var currentUcmType = new FormData(); - currentUcmType.append('client', '" . $this->client . "'); + currentUcmType.append('client', '" . $this->client . "'); var afterCheckCompatibilityOfUcmType = function(error, response){ response = JSON.parse(response); - if (response.data !== null) + if (response.data.length > 0) { jQuery('.copyToOther').removeClass('hide'); jQuery.each(response.data, function(key, value) { @@ -71,15 +71,15 @@ // Code to check ucm type compatibility to copy item com_tjucm.Services.Items.chekCompatibility(currentUcmType, afterCheckCompatibilityOfUcmType); }); - + function copyItem() { var afterCopyItem = function(error, response){ response = JSON.parse(response); - + // Close pop up and display message jQuery( '#copyModal' ).modal('hide'); - + if(response.data !== null) { Joomla.renderMessages({'success':[response.message]}); @@ -89,12 +89,12 @@ function copyItem() Joomla.renderMessages({'error':[response.message]}); } } - + var copyItemData = jQuery('#adminForm').serialize(); - + // Code to copy item to ucm type com_tjucm.Services.Items.copyItem(copyItemData, afterCopyItem); - } + } "); $statusColumnWidth = 0; @@ -108,7 +108,7 @@ function copyItem() ?> - + + - + canEdit || $this->canDelete) - { ?> - items)) - { - echo $this->pagination->getListFooter(); - } + if (!empty($this->items)) + { + echo $this->pagination->getPagesLinks(); + } ?> @@ -286,16 +281,23 @@ class="btn btn-success btn-small"> - - - - - - canImport) + { + ?> + + + - @@ -309,16 +311,16 @@ class="btn btn-success btn-small"> -

Select Ucm Type

+

@@ -327,22 +329,16 @@ class="btn btn-success btn-small"> -canDelete) -{ - ?> - - diff --git a/src/components/com_tjucm/site/views/items/tmpl/default_filters.php b/src/components/com_tjucm/site/views/items/tmpl/default_filters.php index c2391ce9..60c067d3 100644 --- a/src/components/com_tjucm/site/views/items/tmpl/default_filters.php +++ b/src/components/com_tjucm/site/views/items/tmpl/default_filters.php @@ -24,6 +24,9 @@ value="escape($this->state->get($this->client . '.filter.search')); ?>" placeholder=""/> +
- enabled) { JLoader::import('components.com_tjfields.tables.field', JPATH_ADMINISTRATOR); @@ -55,14 +53,54 @@ if ($fieldTable->id) { - JFormHelper::addFieldPath(JPATH_ADMINISTRATOR . '/components/com_tjfields/models/fields/'); - $cluster = JFormHelper::loadFieldType('cluster', false); - $this->clusterList = $cluster->getOptionsExternally(); + JLoader::import("/components/com_subusers/includes/rbacl", JPATH_ADMINISTRATOR); + JLoader::import("/components/com_cluster/includes/cluster", JPATH_ADMINISTRATOR); + $clustersModel = ClusterFactory::model('Clusters', array('ignore_request' => true)); + $clusters = $clustersModel->getItems(); + + // Get list of clusters with data in UCM type + $db = JFactory::getDbo(); + $query = $db->getQuery(true); + $query->select($db->quoteName('cluster_id')); + $query->from($db->quoteName('#__tj_ucm_data')); + $query->where($db->quoteName('client') . '=' . $db->quote($this->client)); + $query->group($db->quoteName('cluster_id')); + $db->setQuery($query); + $clustersWithData = $db->loadColumn(); + + $usersClusters = array(); + + $clusterObj = new stdclass; + $clusterObj->text = JText::_("COM_TJFIELDS_OWNERSHIP_CLUSTER"); + $clusterObj->value = ""; + + $usersClusters[] = $clusterObj; + + if (!empty($clusters)) + { + foreach ($clusters as $clusterList) + { + if (RBACL::check(JFactory::getUser()->id, 'com_cluster', 'core.viewitem.' . $this->ucmTypeId, $clusterList->id) || RBACL::check(JFactory::getUser()->id, 'com_cluster', 'core.viewallitem.' . $this->ucmTypeId)) + { + if (!empty($clusterList->id)) + { + if (in_array($clusterList->id, $clustersWithData)) + { + $clusterObj = new stdclass; + $clusterObj->text = $clusterList->name; + $clusterObj->value = $clusterList->id; + + $usersClusters[] = $clusterObj; + } + } + } + } + } ?>