PageSourceSearch

https://coag.org/Scripts/App/products.js

js coag.org collected 2026-10-01 13:07:05 UTC 8,323 bytes, 253 lines download raw bytes

1App.Products = function(){
2    var lang = App.Localization.getLang();
3    var editorHeight = 530
4
5    function setupEditor(options){
6        var $form = $("#product-editor");
7        var hostId = $("input[name=HostId]", $form).val();
8
9        $form.removeData("validator")
10        $form.removeData("unobtrusiveValidation");
11        $form.validate();
12
13        if (options == null || options.bodyFormat == null || options.bodyFormat == "html" )
14    		$('textarea[name=description]', $form).tinymce({
15                script_url:"/scripts/libs/tinymce/tinymce.min.js",
16                theme: "modern",
17                relative_urls: false,
18                plugins: "link,paste,images,videos,textcolor,colorpicker,pagebreak,tweet,image",
19                image_advtab: true,
20                menu: " ",
21                toolbar1: "bold italic underline | forecolor backcolor | bullist numlist | alignleft aligncenter alignright alignjustify | link unlink ",
22                statusbar: true,
23                height: $(window).height() - editorHeight,
24                convert_urls: false,
25                content_css: "/content/profile-custom-info-editor.css",
26                actor_id: chil.identity.id,
27                formats: {
28                    underline : {inline:'span', 'classes':'underline'},
29                    bold : {inline:'span', 'classes':'bold'},
30                    italic : {inline:'span', 'classes':'italic'},
31                    custom_format: {inline: 'span', 'classes':'remarkable'}
32                },
33                init_instance_callback: function (inst) {
34                    var resizeId;
35                    setTimeout(function () {
36                        window.onresize = function() {
37                            clearTimeout(resizeId);
38                            resizeId = setTimeout(function(){
39                                $("#" + inst.id + '_ifr').animate({
40                                    height: $(window).height() - editorHeight
41                                });
42                            }, 250);
43                        }
44                    }, 1000);
45                }
46            });
47
48        function setupAttachmentsInput(){
49            var $input = $("input[name=attachmentsChange]", $form);
50            if ($input.length === 0)
51            {
52                $input = $("<input></input>").attr({
53                    type: "hidden",
54                    name: "attachmentsChange"
55                })
56                .appendTo($form)
57            }
58        }
59
60        $('.categoriespicker-wrapper .categoriespicker', $form).categoriespicker({
61            hostId: hostId
62        });
63
64        $('.tb-location', $form).tblocation();
65
66        $("input[name=tags]", $form).tagsAutocomplete();
67
68        $(".post-attachments", $form).attachmetns("setupAttachments", {
69            onRemoveAttachment: function(){
70                setupAttachmentsInput();
71            }
72        });
73
74        $(".ch-iconphoto", $form).addFileButton({
75            mobileFormId: "#imgForm",
76            attach: {
77                container: $(".post-attachments", $form),
78                after: function(){
79                    setupAttachmentsInput();
80                }
81            }
82        });
83
84        $(".ch-icondoc", $form).addFileButton({
85            mobileFormId: "#docForm",
86            title: lang.addDocument,
87            fileFormAccept: $.fn.attachmetns.accept.DOCS,
88            popupUrl: "/add-doc",
89            attach: {
90                container: $(".post-attachments", $form),
91                after: function(){
92                    setupAttachmentsInput();
93                }
94            }
95        });
96
97        $(".ch-iconlink", $form).linkAttachment({
98            hostFileId: hostFileId,
99            title: "Attach Link",
100            attach: {
101                container: $(".post-attachments", $form),
102                after: function(){
103                    setupAttachmentsInput();
104                }
105            }
106        });
107
108        $(".ch-iconcloud", $form).attachmetns({
109            container: $(".post-attachments", $form),
110            showUploadSection: false,
111            onRemoveAttachment: function(){
112                setupAttachmentsInput();
113            },
114            onNewAttachments: function(){
115                setupAttachmentsInput();
116            }
117        });
118
119        var hostFileId = chil.identity.id;
120		var pictureUrlSettings = options.coverUrlSettings || "?w=240&h=96&mode=crop";
121
122        function getPictureInput($pictureSelector){
123            var $input = $("input[name=pictureId]", $pictureSelector);
124            if ($input.length === 0)
125            {
126                $input = $("<input></input>").attr({
127                    type: "hidden",
128                    name: "pictureId"
129                })
130                .appendTo($pictureSelector)
131            }
132
133            return $input
134        }
135
136		var $pictureSelector = $(".picture-selector", $form).uploadFileForm({
137			filePickerInPopup: true,
138			hostFileId: hostFileId,
139			returnObject: true,
140			onFileUploaded: function(file){
141				$pictureSelector.uploadFileForm("showUploadedFileAsImg", {
142					file: file,
143					imgUrlSettings: pictureUrlSettings
144				});
145                getPictureInput($pictureSelector) .val(file.id);
146			},
147			onFilesSelected: function(files){
148				if (files != null && files.length > 0)
149					$pictureSelector.uploadFileForm("showSelectedFileAsImg", {
150						file: files[0],
151						imgUrlSettings: pictureUrlSettings,
152						hostFileId: hostFileId,
153						onShowPreview: function(previewUrl){
154                            getPictureInput($pictureSelector).val(files[0].id)
155						}
156					});
157			},
158			onRemove: function(){
159                getPictureInput($pictureSelector).val("");
160			}
161		});
162
163		var $back = $(".action-back", $form).click(function(){
164			if (options.back)
165				window.location.href = options.back;
166			else
167				window.location.href = document.referrer;
168		});
169
170		if (options.back || document.referrer)
171			$back.show();
172
173        function getFeaturesInput(){
174            var $input = $("input[name=features]", $form);
175            if ($input.length === 0)
176            {
177                $input = $("<input></input>").attr({
178                    type: "hidden",
179                    name: "features"
180                })
181                .appendTo($form)
182            }
183
184            return $input
185        }
186
187        $('.feature', $form).on("click", function(){
188            var v = '';
189            $('.feature:checked', $form).each(function(){
190                v = v + $(this).val() + ','
191            })
192            getFeaturesInput().val(v)
193        })
194
195		$form.ajaxForm({
196		    beforeSubmit: function () {
197                $(".button-submit", $form).hide();
198				$(".saving", $form).show();
199			},
200		    success: function (response) {
201				$(".saving", $form).hide();
202				$(".button-submit", $form).show();
203
204                $("input[name=attachmentsChange]", $form).remove()
205
206                if (response.ok){
207					if (response.data){
208						chil.ui.toast(lang.productCreated);
209						document.title = lang.productEditTitle;
210						$(".identity-check", $form).remove();
211						$("h1", $form).html(lang.productEditTitle);
212
213						//$(".status", $form).html(editorStatus[response.data.Status]);
214
215						$form.attr("action", "/update-product");
216						history.pushState(null, null, "/edit-product/" + response.data.Id);
217
218						$("<input></input>").attr({
219							type: "hidden",
220							name: "id",
221							value: response.data.Id
222						}).appendTo($form);
223					}
224					else
225						chil.ui.toast(lang.productUpdated);
226				}
227				else {
228					if (response.error.code == 401)
229						App.Dialogs.alertDialog({
230							type: App.Dialogs.AlertType.FORBIDDEN
231						});
232					else
233						App.Dialogs.alertDialog({
234							type: App.Dialogs.AlertType.ERROR,
235							message: response.error.msg
236						});
237				}
238			},
239			error: function(){
240				$(".saving", $form).hide();
241				$(".button-submit", $form).show();
242				App.Dialogs.alertDialog({
243					type: App.Dialogs.AlertType.ERROR,
244					message: lang.serverError
245				});
246			}
247		});
248    }
249
250    return {
251		setupEditor : setupEditor
252	}
253}();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.