Last active
August 29, 2015 14:14
-
-
Save ercanozkaya/ea640e49f813c3da730e to your computer and use it in GitHub Desktop.
Date field in batch screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kQuery(function($) { | |
var requests = [], | |
flattenArray = function(items){ | |
var object = {}; | |
$.each(items, function(i, item){ | |
object[item.name] = item.value; | |
}); | |
return object; | |
}, | |
getQueryString = function(form, defaults) { | |
var values = flattenArray($(form).serializeArray()); | |
$.each(defaults, function(key, value) { | |
if (!values[key] || values[key] === '') { | |
if (typeof value !== 'undefined') { | |
values[key] = value; | |
} | |
} | |
}); | |
values['storage_type'] = 'file'; | |
return values; | |
}, | |
humanizeString = function(string) { | |
string = string.substring(0, string.lastIndexOf('.')); | |
var last_slash = string.lastIndexOf('/'); | |
if (last_slash) { | |
string = string.substring(last_slash+1); | |
} | |
string = string.replace(/[_\-\.]/g, ' '); | |
string = string[0].toUpperCase()+string.substr(1); | |
return string; | |
}, | |
dehumanizeString = function(string) { | |
var last_slash = string.lastIndexOf('/'); | |
if (last_slash) { | |
string = string.substring(last_slash+1); | |
} | |
return string; | |
}, | |
humanize = function() { | |
$.each($('.document-form'), function(i, el) { | |
var $el = $(el), | |
filename = $el.find('.file-name-input').val(), | |
input = $el.find('input[name=title]'); | |
if (input.val() === dehumanizeString(filename)) { | |
input.val(humanizeString(filename)); | |
} | |
}); | |
}, | |
dehumanize = function() { | |
$.each($('.document-form'), function(i, el) { | |
var $el = $(el), | |
filename = $el.find('.file-name-input').val(), | |
input = $el.find('input[name=title]'); | |
if (input.val() === humanizeString(filename)) { | |
input.val(dehumanizeString(filename)); | |
} | |
}); | |
}; | |
$('#humanized_titles').change(function() { | |
var value = $(this).prop('checked'); | |
value ? humanize() : dehumanize(); | |
}); | |
requests.chain = function(callback){ | |
this.unshift(callback); | |
}; | |
requests.callChain = function() { | |
if (this.length) { | |
this.pop().call(); | |
} | |
}; | |
$('#document_list').find('.cancel').on('click', function(e) { | |
e.preventDefault(); | |
var el = $(e.currentTarget).closest('.document-form'); | |
el.animate({ | |
opacity: 0.2, | |
height: 0 | |
}, 300, function(){ | |
el.remove(); | |
}); | |
}); | |
$('#document-batch').data('controller').implement({ | |
'_actionApply': function() { | |
var batch = $('#document-batch'); | |
select = batch.find('select[name=docman_category_id]'); | |
if (!select.val()) { | |
select.closest('.control-group').addClass('error'); | |
return; | |
} | |
var defaults = flattenArray(batch.serializeArray()); | |
requests.chain(function() { | |
$('#toolbar-apply').find('a').addClass('disabled'); | |
$('select[name="docman_category_id"]').select2('readonly', true); | |
var enabled = batch.find('.btn-group'); | |
enabled.addClass('disabled'); | |
$('label', enabled).unbind('click'); | |
$('input', enabled).attr('disabled', 'disabled'); | |
$('#humanized_titles').attr('disabled', 'disabled'); | |
$('.document-form').each(function(idx, el) { | |
$('input[name="title"]', el).attr('readonly', 'readonly'); | |
$('textarea', el).attr('readonly', 'readonly'); | |
$('select[name="docman_category_id"]').select2('readonly', true); | |
$('select[name="enabled"]').select2('readonly', true); | |
}); | |
}); | |
requests.callChain(); | |
$('form.document-form').each(function(i, form) { | |
requests.chain(function() { | |
$.ajax({ | |
url: 'index.php?option=com_docman&view=document&format=json', | |
type: 'POST', | |
dataType: 'json', | |
data: getQueryString(form, defaults) | |
}).fail(function(){ | |
if(window.console) console.error(this, arguments, form); | |
}).done(function(response, eventStatus, xhr){ | |
if (xhr.status == 201) { | |
var item = response.entities[0], | |
form = $('form.document-form[data-path="'+item.storage_path+'"]'), | |
text = Koowa.translate('Continue editing this document: {document}'); | |
form.empty(); | |
form.append($('<p />').append($('<a />', { | |
'href': 'index.php?option=com_docman&view=document&id='+item.id, | |
'text': text.replace('{document}', item.title), | |
'target': '_blank' | |
}))); | |
} | |
}).always(function(){ | |
requests.callChain(); | |
}); | |
}); | |
}); | |
requests.callChain(); | |
return requests; | |
}, | |
'_actionSave': function() { | |
var self = this; | |
requests = this._actionApply(); | |
requests.chain(function() { | |
self._actionCancel(); | |
}); | |
return requests; | |
}, | |
'_actionCancel': function() { | |
if (!$('form.document-form input[name=title]').length || confirm(Koowa.translate('You will lose all unsaved data. Are you sure?'))) { | |
window.location = 'index.php?option=com_docman&view=files'; | |
} | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
/** | |
* @package DOCman | |
* @copyright Copyright (C) 2011 - 2014 Timble CVBA. (http://www.timble.net) | |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> | |
* @link http://www.joomlatools.com | |
*/ | |
defined('KOOWA') or die; ?> | |
<?= helper('bootstrap.load'); ?> | |
<?= helper('behavior.koowa'); ?> | |
<?= helper('translator.script', array('strings' => array( | |
'You will lose all unsaved data. Are you sure?', | |
'Continue editing this document: {document}' | |
))); ?> | |
<ktml:module position="toolbar"> | |
<ktml:toolbar type="actionbar"> | |
</ktml:module> | |
<ktml:script src="media://com_docman/js/admin/files.form.js" /> | |
<div class="docman_form_layout"> | |
<? if (empty($paths)): ?> | |
<?= translate('You did not select any files. Please go back and select some files first.')?> | |
<? else: ?> | |
<div class="koowa_container koowa_container--medium koowa_container--island"> | |
<form class="-koowa-form" id="document-batch"> | |
<div class="koowa_grid__row"> | |
<div class="koowa_grid__item one-whole"> | |
<fieldset> | |
<legend><?= translate('Batch Values'); ?></legend> | |
<div class="koowa_grid__row"> | |
<div class="control-group koowa_grid__item one-whole"> | |
<label class="control-label"><?= translate('Category');?>:</label> | |
<div class="controls"> | |
<?= helper('listbox.categories', array( | |
'name' => 'docman_category_id', | |
'deselect' => false, | |
'attribs' => array('class' => 'required') | |
))?> | |
</div> | |
</div> | |
</div> | |
<div class="koowa_grid__row"> | |
<div class="control-group koowa_grid__item one-whole"> | |
<label class="control-label"><?= translate('Status');?>:</label> | |
<div class="controls radio btn-group"> | |
<?= helper('select.booleanlist', array( | |
'name' => 'enabled', | |
'selected' => 1, | |
'true' => 'Published', | |
'false' => 'Unpublished' | |
)); ?> | |
</div> | |
</div> | |
</div> | |
<div class="koowa_grid__row"> | |
<div class="control-group koowa_grid__item one-whole"> | |
<label class="control-label"><?= translate('Date');?>:</label> | |
<div class="controls radio btn-group"> | |
<?= helper('behavior.calendar', array( | |
'name' => 'created_on', | |
'id' => 'created_on', | |
'format' => '%Y-%m-%d %H:%M:%S', | |
'filter' => 'user_utc', | |
'value' => 'now' | |
))?> | |
</div> | |
</div> | |
</div> | |
<div class="koowa_grid__row"> | |
<div class="control-group koowa_grid__item one-whole"> | |
<label class="control-label"><?= translate('Publish on');?>:</label> | |
<div class="controls radio btn-group"> | |
<?= helper('behavior.calendar', array( | |
'name' => 'publish_on', | |
'id' => 'publish_on', | |
'format' => '%Y-%m-%d %H:%M:%S', | |
'filter' => 'user_utc', | |
'value' => 'now' | |
))?> | |
</div> | |
</div> | |
</div> | |
<div class="koowa_grid__row"> | |
<div class="control-group koowa_grid__item one-whole"> | |
<div class="controls"> | |
<label for="humanized_titles"> | |
<input type="checkbox" id="humanized_titles" checked /> | |
<?= translate('Human readable titles'); ?> | |
<small>(document-2013-07-08.pdf » Document 2013 07 08)</small> | |
</label> | |
</div> | |
</div> | |
</div> | |
</fieldset> | |
</div> | |
</div> | |
</form> | |
</div> | |
<div class="koowa_secondary_container"> | |
<div class="koowa_container koowa_container--medium koowa_container--island"> | |
<div class="koowa_grid__row"> | |
<div class="koowa_grid__item one-whole"> | |
<legend><?= translate('Documents'); ?></legend> | |
<div id="document_list"> | |
<div class="koowa_grid__row"> | |
<? $i=0;foreach ((array)KObjectConfig::unbox($paths) as $path): ?> | |
<div class="koowa_grid__item one-third"> | |
<form class="form-vertical document-form" method="post" id="form<?= $i?>" data-path="<?= escape($path) ?>"> | |
<div class="control-group"> | |
<button class="cancel btn btn-mini docman_tooltip" title="<?= translate('Remove this file from the list');?>"><i class="icon icon-minus-sign"></i></button> | |
</div> | |
<div class="control-group"> | |
<label class="control-label"><?= translate('File name');?>:</label> | |
<div class="controls"> | |
<input class="disabled input-block-level file-name-input" type="text" value="<?= escape($path); ?>" disabled/> | |
</div> | |
</div> | |
<div class="control-group"> | |
<label for="docman_title<?= $i?>" class="control-label"><?= translate('Title');?>:</label> | |
<div class="controls"> | |
<input id="docman_title<?= $i?>" class="input-block-level" type="text" name="title" value="<?= escape(helper('string.humanize', array( | |
'string' => $path, 'strip_extension' => true))); ?>" /> | |
</div> | |
</div> | |
<div class="control-group"> | |
<label for="docman_description<?= $i?>" class="control-label"><?= translate('Description');?>:</label> | |
<div class="controls"> | |
<textarea id="docman_description<?= $i?>" class="input-block-level" style="resize:vertical;" name="description"></textarea> | |
</div> | |
</div> | |
<div class="control-group"> | |
<label class="control-label"><?= translate('Category');?>:</label> | |
<div class="controls"> | |
<?= helper('listbox.categories', array( | |
'attribs' => array('id' => 'docman_category_id_'.$i), | |
'name' => 'docman_category_id', | |
'selected' => '', | |
'prompt' => translate('- Use Batch Value -') | |
))?> | |
</div> | |
</div> | |
<div class="control-group"> | |
<label class="control-label"><?= translate('Status');?>:</label> | |
<div class="controls"> | |
<?= helper('listbox.optionlist', array( | |
'select2' => true, | |
'name' => 'enabled', | |
'prompt' => translate('- Use Batch Value -'), | |
'attribs' => array('class' => 'input-block-level'), | |
'deselect' => true, | |
'options' => array( | |
array('value' => 1, 'label' => translate('Published')), | |
array('value' => 0, 'label' => translate('Unpublished')) | |
) | |
))?> | |
</div> | |
</div> | |
<input type="hidden" name="storage_path" value="<?= escape($path); ?>" /> | |
<input type="hidden" name="automatic_thumbnail" value="1" /> | |
</form> | |
</div> | |
<? $i++;endforeach; ?> | |
</div> | |
</div> | |
<? endif; ?> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment