<?php
global $config;
if (!$config) {exit();}
?>
FR.customActions.pdf_split.run = function() {
	this.prompt = new Ext.Window({
		title: '<?php echo \S::safeJS($this->JSconfig['title']);?>',
		closable: false,
		resizable: false,
		maximized: FR.UI.layout.isPhone,
		items: [
			{
				xtype: 'form',
				items: [
					{
						xtype: 'textfield',
						name: 'pages',
						ref: '../textfield',
						width: 180,
						fieldLabel: '<?php echo \S::safeJS(self::t("Pages to extract"));?>',
						helpText: 'It can be a range of pages (<b>1-5</b> or <b>5-1</b>), or a list of separate pages (<b>1</b>,<b>2</b>,<b>3</b>), or any combination of ranges and separate pages (<b>1</b>, <b>5-10</b>).'
					},
					{
						xtype: 'checkbox',
						name: 'split',
						value: true,
						inputValue: '1',
						fieldLabel: '&nbsp;',
						boxLabel: '<?php echo \S::safeJS(self::t("Each page in a separate file"));?>'
					}
				]
			}
		],
		bbar: [
			{
				text: 'Ok',
				cls: 'fr-btn-primary',
				handler: () => this.doAction()
			},
			{
				text: 'Cancel',
				handler : () => this.prompt.hide()
			}
			],
		listeners: {
			'show': (p) => p.textfield.focus()
		}
	});
	this.prompt.show();
};
FR.customActions.pdf_split.doAction = function() {
	FR.actions.processGridItemsByPaths({
		url: '/?module=custom_actions&action=pdf_split&method=split',
		params: this.prompt.items.first().getFieldValues()
	});
	this.prompt.hide();
}