-
Notifications
You must be signed in to change notification settings - Fork 11
/
EditSettings.ascx
157 lines (149 loc) · 7.31 KB
/
EditSettings.ascx
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<%@ Control Language="C#" AutoEventWireup="false" Inherits="Satrabel.OpenForm.EditSettings" CodeBehind="EditSettings.ascx.cs" %>
<%@ Register TagPrefix="dnn" TagName="Label" Src="~/controls/LabelControl.ascx" %>
<%@ Register TagPrefix="dnncl" Namespace="DotNetNuke.Web.Client.ClientResourceManagement" Assembly="DotNetNuke.Web.Client" %>
<asp:Panel ID="ScopeWrapper" runat="server">
<div class="dnnFormItem">
<dnn:Label ID="scriptListLabel" ControlName="scriptList" runat="server" />
<asp:DropDownList ID="scriptList" runat="server" />
<asp:HyperLink ID="hlTemplateExchange" runat="server">More...</asp:HyperLink>
</div>
<div id="field1" class="alpaca"></div>
<asp:CustomValidator ID="CustomValidator" runat="server" ErrorMessage="CustomValidator" ControlToValidate="scriptList" ClientValidationFunction="ClientValidation"></asp:CustomValidator>
<asp:HiddenField ID="HiddenField" runat="server" />
<ul class="dnnActions dnnClear" style="display: block; padding-left: 35%">
<li>
<asp:LinkButton ID="cmdSave" runat="server" class="dnnPrimaryAction" resourcekey="cmdSave" OnClick="cmdSave_Click" /></li>
<li>
<asp:HyperLink ID="hlCancel" runat="server" class="dnnSecondaryAction" resourcekey="cmdCancel" />
</li>
</ul>
</asp:Panel>
<script type="text/javascript">
function ClientValidation(sender, args) {
var alp = $("#field1").alpaca("get");
if (alp) {
alp.refreshValidationState(true);
if (alp.isValid(true)) {
var value = alp.getValue();
$("#<%= HiddenField.ClientID %>").val(JSON.stringify(value, null, " "));
return;
}
args.IsValid = false;
}
return;
}
/*globals jQuery, window, Sys */
(function ($, Sys) {
function setupStructSettings() {
var moduleScope = $('#<%=ScopeWrapper.ClientID %>'),
self = moduleScope,
sf = $.ServicesFramework(<%=ModuleId %>);
$("#<%= scriptList.ClientID %>").change(function () {
$("#field1").alpaca("destroy");
self.CreateForm();
});
self.CreateForm = function () {
var Template = $("#<%= scriptList.ClientID %>").val();
if (!Template) return;
var postData = {};
var getData = "Template=" + Template;
var action = "Settings";
$.ajax({
type: "GET",
url: sf.getServiceRoot('OpenForm') + "OpenFormAPI/" + action,
data: getData,
beforeSend: sf.setModuleHeaders
}).done(function (config) {
if (config.schema) {
var ConnectorClass = Alpaca.getConnectorClass("default");
connector = new ConnectorClass("default");
connector.servicesFramework = sf;
$.alpaca.Fields.DnnFileField = $.alpaca.Fields.FileField.extend({
setup: function () {
this.base();
},
afterRenderControl: function (model, callback) {
var self = this;
this.base(model, function () {
self.handlePostRender(function () {
callback();
});
});
},
handlePostRender: function (callback) {
//var self = this;
var el = this.control;
self.SetupFileUpload(el);
callback();
}
});
Alpaca.registerFieldClass("file", Alpaca.Fields.DnnFileField);
$("#field1").alpaca({
"schema": config.schema,
"options": config.options,
"data": config.data,
"view": "dnnbootstrap-edit",
"connector": connector,
"postRender": function (control) {
}
});
}
}).fail(function (xhr, result, status) {
alert(status + " : " + xhr.responseText);
});
};
self.FormSubmit = function (data, href) {
var postData = { form: data };
var action = "Update";
$.ajax({
type: "POST",
url: sf.getServiceRoot('OpenForm') + "OpenFormAPI/" + action,
data: postData,
beforeSend: sf.setModuleHeaders
}).done(function (data) {
window.location.href = href;
}).fail(function (xhr, result, status) {
alert("Uh-oh, something broke: " + status + " " + xhr.responseText);
});
};
self.SetupFileUpload = function (fileupload) {
$(fileupload).fileupload({
dataType: 'json',
url: sf.getServiceRoot('Satrabel.Content') + "FileUpload/UploadFile",
maxFileSize: 25000000,
formData: { example: 'test' },
beforeSend: sf.setModuleHeaders,
add: function (e, data) {
//data.context = $(opts.progressContextSelector);
//data.context.find($(opts.progressFileNameSelector)).html(data.files[0].name);
//data.context.show('fade');
data.submit();
},
progress: function (e, data) {
if (data.context) {
var progress = parseInt(data.loaded / data.total * 100, 10);
data.context.find(opts.progressBarSelector).css('width', progress + '%').find('span').html(progress + '%');
}
},
done: function (e, data) {
if (data.result) {
$.each(data.result, function (index, file) {
//$('<p/>').text(file.name).appendTo($(e.target).parent().parent());
//$('<img/>').attr('src', file.url).appendTo($(e.target).parent().parent());
$(e.target).closest('.alpaca-container').find('.alpaca-field-image input').val(file.url);
$(e.target).closest('.alpaca-container').find('.alpaca-image-display img').attr('src', file.url);
});
}
}
}).data('loaded', true);
}
self.CreateForm();
}
$(document).ready(function () {
setupStructSettings();
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function () {
setupStructSettings();
});
});
}(jQuery, window.Sys));
</script>