forked from ezsystems/ezpublish-legacy
/
ezobjectrelation_ajaxuploader.tpl
113 lines (100 loc) · 5.25 KB
/
ezobjectrelation_ajaxuploader.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{* DO NOT EDIT THIS FILE! Use an override template instead. *}
{if ezmodule( 'ezjscore' )}
<input type="submit" value="{'Upload a file'|i18n( 'design/admin/content/datatype' )}"
name="RelationUploadNew{$attribute.id}-{$attribute.version}"
class="button simple-relation-upload-new hide"
{cond( $enabled, '', 'disabled="disabled"' )}
title="{'Upload a file to create a new object and add it to the relation'|i18n( 'design/admin/content/datatype' )}" />
{run-once}
{ezscript_require( array( 'ezjsc::yui3', 'ezjsc::yui3io', 'ezmodalwindow.js', 'ezajaxuploader.js' ) )}
<div id="relation-modal-window" class="modal-window" style="display:none;">
<h2><a href="#" class="window-close">{'Close'|i18n( 'design/admin/pagelayout' )}</a><span></span></h2>
<div class="window-content"></div>
</div>
<script type="text/javascript">
{literal}
(function () {
YUI(YUI3_config).use('ezmodalwindow', 'ezajaxuploader', function (Y) {
// move modal-window outside the form (add it to the body node)
var modalwindow = Y.one('#relation-modal-window');
Y.one(document.body).append( modalwindow.cloneNode(true) );
modalwindow.remove();
var uploaderConf = {
target: {},
open: {
action: 'ezajaxuploader::uploadform::ezobjectrelation'
},
upload: {
action: 'ezajaxuploader::upload::ezobjectrelation?ContentType=html',
form: 'form.ajaxuploader-upload'
},
location: {
action: 'ezajaxuploader::preview::ezobjectrelation',
form: 'form.ajaxuploader-location',
browse: 'div.ajaxuploader-browse',
{/literal}
required: "{'Please choose a location'|i18n( 'design/admin/content/datatype' )|wash( 'javascript' )}"
{literal}
},
preview: {
form: 'form.ajaxuploader-preview',
// this is the eZAjaxUploader instance
callback: function () {
var box = Y.one('#ezobjectrelation_browse_' + this.conf.target.ObjectRelationsAttributeId),
table = box.one('table.list');
tbody = box.one('table.list tbody'),
tds = tbody.get('children').slice(-1).item(0).get('children');
result = this.lastMetaData;
table.removeClass('hide');
tds.item(0).setContent(result.object_info.name);
tds.item(1).setContent(result.object_info.class_name);
tds.item(2).setContent(result.object_info.section_name);
tds.item(3).setContent(result.object_info.published);
box.one('input[name*=_data_object_relation_id_]').set('value', result.object_info.id);
box.one('.ezobject-relation-remove-button').removeClass('button-disabled').addClass('button').set('disabled', false);
box.all('.ezobject-relation-no-relation').addClass('hide');
box.one('.ezobject-relation-add-button').addClass('button-disabled').set('disabled', true);
box.one('.simple-relation-upload-new').addClass('button-disabled').set('disabled', true);
this.modalWindow.close();
}
},
{/literal}
validationErrorText: "{'Some required fields are empty.'|i18n( 'design/admin/content/datatype' )|wash( 'javascript' )}",
parseJSONErrorText: "{'Unable to parse the JSON response.'|i18n( 'design/admin/content/datatype' )|wash( 'javascript' )}",
title: "{'Upload a file and add the resulting object in the relation'|i18n( 'design/admin/content/datatype' )|wash( 'javascript' )}"
{literal}
};
var windowConf = {
window: '#relation-modal-window',
centered: false,
xy: ['centered', 50],
width: 650
};
Y.on('domready', function() {
var win = new Y.eZ.ModalWindow(windowConf, Y),
tokenNode = Y.one('#ezxform_token_js');
Y.all('.simple-relation-upload-new').each(function () {
var data = this.get('name').replace("RelationUploadNew", '').split("-"),
conf = Y.clone(uploaderConf, true),
uploader;
conf.target = {
ObjectRelationsAttributeId: data[0],
Version: data[1]
};
if ( tokenNode ) {
conf.token = tokenNode.get('title');
}
uploader = new Y.eZ.AjaxUploader(win, conf, Y);
this.on('click', function (e) {
uploader.open();
e.halt();
});
this.removeClass('hide');
});
});
});
})();
{/literal}
</script>
{/run-once}
{/if}