Keyword

Frontend Save & Close solution

  • Martijn Hartong
  • Martijn Hartong's Avatar Topic Author
  • Offline
  • New Member
More
5 years 1 month ago - 5 years 1 month ago #171292 by Martijn Hartong
Frontend Save & Close solution was created by Martijn Hartong
Hi,

For my project I really needed a working Save & Close button with visible reloaded content. I read a lot of questions, but could not find the answer. Basicly there are two save buttons; one with hover class and the other sets local storage. Perhaps it's better with User state and/or setInterval, etc. Please find my html/js from itemform.php to discuss better solutions. Thanks
<table id="k2ModalToolbar" cellpadding="2" cellspacing="4">
			<tr>
				<td id="toolbar-save" class="button">
					<a href="#" onclick="Joomla.submitbutton('save');return false;">
						<i class="fa fa-check" aria-hidden="true"></i> <?php echo JText::_('K2_SAVE'); ?>
					</a>
				</td>
				<td id="toolbar-cancel" class="button">
					<a href="#">
						<i class="fa fa-times-circle" aria-hidden="true"></i> <?php echo JText::_('K2_CLOSE'); ?>
					</a>
				</td>
                <td id="toolbar-senc" class="button">
					<a href="#" onclick="Joomla.submitbutton('save');return false;">
						<i class="fa fa-bullseye" aria-hidden="true"></i> Save & Close
					</a>
				</td>
			</tr>
		</table>
$document->addScriptDeclaration("
	window.addEvent('domready',function () {
       	\$K2('#catid option').attr('selected', '1');
       	setTimeout(function(){
  		\$K2('#catid').change();
		}, 1000);
    });
	\$K2(function(){
    	\$K2('#toolbar-save').hover(
        function(){ $(this).addClass('active') },
        function(){ $(this).removeClass('active') }
		)
		if (localStorage.getItem('save')) {
			var k2ItemId = \$K2('input[name=id]').val();
			var sigProFolder = \$K2('input[name=sigProFolder]').val();	
            \$K2.ajax({
            	type: 'get',
                cache: false,
                url: K2SitePath + 'index.php?option=com_k2&view=item&task=checkin&cid=' +  k2ItemId + '&lang=' + \$K2('input[name=lang]').val()  + '&sigProFolder=' + sigProFolder,
                success: function() {
                   localStorage.removeItem('save');
                // Close modal
                    if (typeof(parent.\$K2.magnificPopup) !== 'undefined') {
                    	parent.window.location.reload();
                        parent.\$K2.magnificPopup.close();
                        }
                // Close window/tab
                    	if (top == self) {
                     		window.close();
                	}
		// localStorage.removeItem('save') MOVED UP AFTER SUCCESS FOR BROWSER COMPATIBILITY
               	}
         	});
		}
	});
	Joomla.submitbutton = function(pressbutton){
		if (pressbutton == 'cancel') {
			submitform( pressbutton );
			return;
		}
		if (\$K2.trim(\$K2('#title').val()) == '') {
			alert( '".JText::_('K2_ITEM_MUST_HAVE_A_TITLE', true)."' );
		}
		if (\$K2.trim(\$K2('#catid').val()) == '0') {
			alert( '".JText::_('K2_PLEASE_SELECT_A_CATEGORY', true)."' );
		}
		else if (\$K2('#toolbar-save').hasClass('active')) {
			syncExtraFieldsEditor();
			var validation = validateExtraFields();
			if(validation === true) {
				\$K2('#selectedTags option').attr('selected', 'selected');
				submitform( pressbutton );
			}			
		}
		else {
			syncExtraFieldsEditor();
			var validation = validateExtraFields();
			if(validation === true) {
				\$K2('#selectedTags option').attr('selected', 'selected');
				localStorage.setItem('save', 'itemsaved');
				submitform( pressbutton );				
			}
		}
	}
	
");
Last edit: 5 years 1 month ago by Martijn Hartong. Reason: // localStorage.removeItem('save') MOVED UP AFTER SUCCESS FOR BROWSER COMPATIBILITY

Please Log in or Create an account to join the conversation.

More
5 years 1 month ago #171307 by JoomlaWorks
Replied by JoomlaWorks on topic Frontend Save & Close solution
Can you please make a "pull request" here? github.com/getk2/k2/pulls

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum