macro_viewer_js

   Usages of this macro
... in macro_viewer.naml
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<macro name="macro_viewer_js">
    <script type="text/javascript">
        var isCustomTweak = <n.is_custom_tweak
Binary
Namespace: MacroSourceNamespace
/>;
        var pBase = '&base=<n.hide_null
Binary
Namespace: BasicNamespace
Parameters: value
.current_base_classes
Macro
/>';
        var pBreadcrumbs = '<n.hide_null
Binary
Namespace: BasicNamespace
Parameters: value
.current_breadcrumbs
Macro
/>';
        pBreadcrumbs = pBreadcrumbs == ''? '' : '&breadcrumbs=' + pBreadcrumbs;
        var isSiteAdmin = <n.visitor
Binary
Namespace: ServletNamespace
Parameters: do
.is_site_admin
Macro
Requires: user
/>;
 
        var tweakFileContents = "<n.javascript_string_encode
Binary
Namespace: NabbleNamespace
Parameters: text
.hide_null
Binary
Namespace: BasicNamespace
Parameters: value
.tweak_file_contents
Binary
Namespace: MacroSourceNamespace
/>";
        var macroOpeningTag = "<n.javascript_string_encode
Binary
Namespace: NabbleNamespace
Parameters: text
.hide_null
Binary
Namespace: BasicNamespace
Parameters: value
.macro_opening_tag
Binary
Namespace: MacroSourceNamespace
/>";
        $(document).ready(function() {
            function lineSelector(e) {
                return 'div.line'+e.id.substring(8);
            };
            var $lineDivs = $('table.code div.line-contents');
            $lineDivs.hover(
                function() { $(lineSelector(this), $(this).parent().prev()).css('font-weight','bold').addClass('dark-bg-color'); },
                function() { $(lineSelector(this), $(this).parent().prev()).css('font-weight','normal').removeClass('dark-bg-color'); }
            );
            function fixHeights() {
                $lineDivs.each(function() {
                    var h = $(this).outerHeight();
                    var $table = $(this).parents('table');
                    $(lineSelector(this), $table).height(h);
                });
            }
            $(window).resize(fixHeights);
            fixHeights();
 
            var $textarea = $('#txt_basic');
            var textareaValue = $textarea.val().replace(/\s*/g, '');
            var originalFileContents = tweakFileContents.replace(/\s*/g, '');
            if (textareaValue != originalFileContents) {
                showEditor();
            }
            window.onbeforeunload = function() {
                $textarea.val(basicEditor.getCode());
            };
        });
 
        function openNamlLogin() {
            $('#naml-login').slideDown();
        };
 
        function showEditor() {
            if (!isSiteAdmin) {
                openNamlLogin();
                return;
            }
            $('#saveButton,#cancelButton,#wrapping_basic,#resizebar').show();
            $('#editButton,#removeButton').hide();
            if (isCustomTweak)
                $('#current-source').hide();
            else
                $('#overrides-arrow').show();
            var line = getLineNumber(tweakFileContents, macroOpeningTag);
            inlineEditor('20em', line);
        };
        function saveChanges() {
            notice('Saving... Please wait');
            var call = '/template/NamlServlet.jtp?macro=save_tweak&id=<n.id
Binary
Namespace: MacroSourceNamespace
/>' + pBase + pBreadcrumbs + Nabble.getClientID();
            var code = basicEditor.getCode();
            if (code.match(/^\s*$/) != null) {
                notice('Error Found', 3000, 1500);
                var msg = "Error: invalid macro code.";
                $('#error-box').html(msg).show();
                return;
            }
            var params = { contents: code };
            $.post(call, params,
                function(data) {
                    var result = eval('(' + data + ')');
                    if (result.error != null) {
                        notice('Error Found', 3000, 1500);
                        var $errorBox = $('#error-box');
                        $errorBox.html(formatError(result.error)).show();
                        if ($errorBox.height() > 150) {
                            $errorBox.css('overflow-y','scroll').height(150);
                        }
                    } else {
                        pBase = result.base == null? pBase : '&base=' + result.base;
                        pBreadcrumbs = result.breadcrumbs == null? pBreadcrumbs : '&breadcrumbs=' + result.breadcrumbs;
                        var url = '/template/NamlServlet.jtp?macro=macro_viewer&id=' + result.macroId + pBase + pBreadcrumbs + Nabble.getClientID();
                        window.location = url;
                    }
                }
            );
        };
        function cancelChanges() {
            $('#saveButton,#cancelButton,#wrapping_basic,#resizebar,#error-box').hide();
            $('#editButton,#removeButton').show();
            if (isCustomTweak)
                $('#current-source').show();
            else
                $('#overrides-arrow').hide();
            basicEditor.setCode(tweakFileContents);
        };
        function removeOverride() {
            if (!isSiteAdmin) {
                openNamlLogin();
                return;
            }
            <n.if
Binary
Namespace: BasicNamespace
Parameters: condition, else, then
.is_override
Binary
Namespace: MacroSourceNamespace
>
                <then>
                    var confirmQuestion = "Do you really want to remove this override?";
                    var nextUrl = "<n.use_text_encoder
Binary
Namespace: BasicNamespace
Parameters: text
.path_to_overridden_macro
Macro
/>";
                </then>
                <else>
                    var confirmQuestion = "Do you really want to remove this macro?";
                    var nextUrl = "<n.use_text_encoder
Binary
Namespace: BasicNamespace
Parameters: text
.macro_deleted_path
Macro
/>";
                </else>
            </n.if.is_override>
            if( !confirm(confirmQuestion) )
                return;
            var call = '/template/NamlServlet.jtp?macro=revert_tweak&id=<n.id
Binary
Namespace: MacroSourceNamespace
/>' + pBase + pBreadcrumbs + Nabble.getClientID();
            $.get(call, function(data) {
                if (Nabble.trim(data) == 'ok')
                    window.location = nextUrl + Nabble.getClientID();
            });
        };
    </script>
</macro>