Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image type #26

Merged
merged 7 commits into from Feb 24, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions script.js
Expand Up @@ -4,4 +4,16 @@ jQuery(function(){
jQuery('input.struct_date').datepicker({
dateFormat: 'yy-mm-dd'
});

jQuery('button.struct_img').click(function (event) {
var input_id = event.target.id.substr(0,event.target.id.length-'Button'.length);
window.open(
DOKU_BASE+"lib/exe/mediamanager.php?ns=:"+'&edid='+encodeURIComponent(input_id) + '&onselect=insertStructImage',
'mediaselect',
'width=750,height=500,left=20,top=20,scrollbars=yes,resizable=yes'); //
});

window.insertStructImage = function(edid, mediaid, opts, align) {
jQuery('#'+edid).val(mediaid).change();
};
});
49 changes: 49 additions & 0 deletions types/Img.php
@@ -0,0 +1,49 @@
<?php
namespace plugin\struct\types;

use plugin\struct\meta\ValidationException;

class Img extends AbstractBaseType {

protected $config = array(
);

/**
* Output the stored data
*
* @param string|int $value the value stored in the database
* @param \Doku_Renderer $R the renderer currently used to render the data
* @param string $mode The mode the output is rendered in (eg. XHTML)
* @return bool true if $mode could be satisfied
*/
public function renderValue($value, \Doku_Renderer $R, $mode) {
if (!empty($value)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we do not render empty values? We should set up some rules on what types do not need to check themselves (like validate() is never called for blank fields).

if (strpos($value, '://') === false) {
$R->internalmedia($value);
} else {
$R->externalmedia($value);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, now I understand what you meant. There's an easier way. The renderer object you are passed here is the same object you used earlier in startScope. You could simply store the hash in $renderer->info['struct_table_hash'] in startScope and remove it again in stopScope. Later check here, if the value is set and act accordingly.

}
return true;
}

/**
* Return the editor to edit a single value
*
* @param string $name the form name where this has to be stored
* @param string $value the current value
* @return string html
*/
public function valueEditor($name, $value) {
$name = hsc($name);
$value = hsc($value);

$id = preg_replace('(\[|\])','',substr($name,strpos($name,'[')+1));

$html = "<input id=\"$id\" class=\"struct_img\" name=\"$name\" value=\"$value\" />";
$html .= "<button type=\"button\" class=\"struct_img\" id=\"$id"."Button\">";
$html .= "<img src=\"" . DOKU_BASE . "lib/images/toolbar/image.png\" height=\"16\" width=\"16\">";
$html .= "</button>";
return $html;
}
}