This file is indexed.

/usr/lib/python2.7/dist-packages/notebook/static/base/js/dialog.js is in python-notebook 5.2.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

define(['jquery',
    'codemirror/lib/codemirror',
    'bootstrap',
	'base/js/i18n'],
	function($, CodeMirror, bs, i18n) {
    "use strict";

    /**
     * A wrapper around bootstrap modal for easier use
     * Pass it an option dictionary with the following properties:
     *
     *    - body : <string> or <DOM node>, main content of the dialog
     *            if pass a <string> it will be wrapped in a p tag and
     *            html element escaped, unless you specify sanitize=false
     *            option.
     *    - title : Dialog title, default to empty string.
     *    - buttons : dict of btn_options who keys are button label.
     *            see btn_options below for description
     *    - open : callback to trigger on dialog open.
     *    - destroy:
     *    - notebook : notebook instance
     *    - keyboard_manager: keyboard manager instance.
     *
     *  Unlike bootstrap modals, the backdrop options is set by default 
     *  to 'static'.
     *
     *  The rest of the options are passed as is to bootstrap modals. 
     *
     *  btn_options: dict with the following property:
     *  
     *    - click : callback to trigger on click
     *    - class : css classes to add to button.
     *
     *
     *
     **/
    var modal = function (options) {

        var modal = $("<div/>")
            .addClass("modal")
            .addClass("fade")
            .attr("role", "dialog");
        var dialog = $("<div/>")
            .addClass("modal-dialog")
            .appendTo(modal);
        var dialog_content = $("<div/>")
            .addClass("modal-content")
            .appendTo(dialog);
        if(typeof(options.body) === 'string' && options.sanitize !== false){
            options.body = $("<p/>").text(options.body);
        }
        dialog_content.append(
            $("<div/>")
                .addClass("modal-header")
                .mousedown(function() {
                  $(".modal").draggable({handle: '.modal-header'});
                })
                .append($("<button>")
                    .attr("type", "button")
                    .addClass("close")
                    .attr("data-dismiss", "modal")
                    .attr("aria-hidden", "true")
                    .html("&times;")
                ).append(
                    $("<h4/>")
                        .addClass('modal-title')
                        .text(options.title || "")
                )
        ).append(
            $("<div/>")
                .addClass("modal-body")
                .append(
                    options.body || $("<p/>")
                )
        );
        
        var footer = $("<div/>").addClass("modal-footer");
        
        var default_button;
        
        for (var label in options.buttons) {
            var btn_opts = options.buttons[label];
            var button = $("<button/>")
                .addClass("btn btn-default btn-sm")
                .attr("data-dismiss", "modal")
                .text(i18n.msg.translate(label).fetch());
            if (btn_opts.id) {
                button.attr('id', btn_opts.id);
            }
            if (btn_opts.click) {
                button.click($.proxy(btn_opts.click, dialog_content));
            }
            if (btn_opts.class) {
                button.addClass(btn_opts.class);
            }
            footer.append(button);
            if (options.default_button && label === options.default_button) {
                default_button = button;
            }
        }
        if (!options.default_button) {
            default_button = footer.find("button").last();
        }
        dialog_content.append(footer);
        // hook up on-open event
        modal.on("shown.bs.modal", function () {
            setTimeout(function () {
                default_button.focus();
                if (options.open) {
                    $.proxy(options.open, modal)();
                }
            }, 0);
        });
        
        // destroy modal on hide, unless explicitly asked not to
        if (options.destroy === undefined || options.destroy) {
            modal.on("hidden.bs.modal", function () {
                modal.remove();
            });
        }
        modal.on("hidden.bs.modal", function () {
            if (options.notebook) {
                var cell = options.notebook.get_selected_cell();
                if (cell) cell.select();
            }
            if (options.keyboard_manager) {
                options.keyboard_manager.enable();
                options.keyboard_manager.command_mode();
            }
        });
        
        if (options.keyboard_manager) {
            options.keyboard_manager.disable();
        }
        
        if(options.backdrop === undefined){
          options.backdrop = 'static';
        }
        
        return modal.modal(options);
    };

    var kernel_modal = function (options) {
        /**
         * only one kernel dialog should be open at a time -- but
         * other modal dialogs can still be open
         */
        $('.kernel-modal').modal('hide');
        var dialog = modal(options);
        dialog.addClass('kernel-modal');
        return dialog;
    };

    var edit_metadata = function (options) {
        options.name = options.name || "Cell";
        var error_div = $('<div/>').css('color', 'red');
        var message_cell = 
            i18n.msg._("Manually edit the JSON below to manipulate the metadata for this cell.");
        var message_notebook = 
            i18n.msg._("Manually edit the JSON below to manipulate the metadata for this notebook.");
        var message_end = 
            i18n.msg._(" We recommend putting custom metadata attributes in an appropriately named substructure," +
            " so they don't conflict with those of others.");

        var message;
        if (options.name === 'Notebook') {
        	message = message_notebook + message_end;
        } else {
        	message = message_cell + message_end;
        }
        var textarea = $('<textarea/>')
            .attr('rows', '13')
            .attr('cols', '80')
            .attr('name', 'metadata')
            .text(JSON.stringify(options.md || {}, null, 2));
        
        var dialogform = $('<div/>').attr('title', i18n.msg._('Edit the metadata'))
            .append(
                $('<form/>').append(
                    $('<fieldset/>').append(
                        $('<label/>')
                        .attr('for','metadata')
                        .text(message)
                        )
                        .append(error_div)
                        .append($('<br/>'))
                        .append(textarea)
                    )
            );
        var editor = CodeMirror.fromTextArea(textarea[0], {
            lineNumbers: true,
            matchBrackets: true,
            indentUnit: 2,
            autoIndent: true,
            mode: 'application/json',
        });
        var title_msg;
        if (options.name === "Notebook") {
        	title_msg = i18n.msg._("Edit Notebook Metadata");
        } else {
        	title_msg = i18n.msg._("Edit Cell Metadata");
        }
        // This statement is used simply so that message extraction
        // will pick up the strings.
        var button_labels = [ i18n.msg._("Cancel"), i18n.msg._("Edit"), i18n.msg._("OK"), i18n.msg._("Apply")];
        var modal_obj = modal({
            title: title_msg,
            body: dialogform,
            default_button: "Cancel",
            buttons: {
                Cancel: {},
                Edit: { class : "btn-primary",
                    click: function() {
                        /**
                         * validate json and set it
                         */
                        var new_md;
                        try {
                            new_md = JSON.parse(editor.getValue());
                        } catch(e) {
                            console.log(e);
                            error_div.text(i18n.msg._('WARNING: Could not save invalid JSON.'));
                            return false;
                        }
                        options.callback(new_md);
                    }
                }
            },
            notebook: options.notebook,
            keyboard_manager: options.keyboard_manager,
        });

        modal_obj.on('shown.bs.modal', function(){ editor.refresh(); });
    };

    var edit_attachments = function (options) {
        // This shows the Edit Attachments dialog. This dialog allows the
        // user to delete attachments. We show a list of attachments to
        // the user and he can mark some of them for deletion. The deletion
        // is applied when the 'Apply' button of this dialog is pressed.
        var message;
        var attachments_list;
        if (Object.keys(options.attachments).length == 0) {
            message = i18n.msg._("There are no attachments for this cell.");
            attachments_list = $('<div>');
        } else {
            message = i18n.msg._("Current cell attachments");

            attachments_list = $('<div>')
                .addClass('list_container')
                .append(
                    $('<div>')
                    .addClass('row list_header')
                    .append(
                        $('<div>')
                        .text(i18n.msg._('Attachments'))
                    )
                );

            // This is a set containing keys of attachments to be deleted when
            // the Apply button is clicked
            var to_delete = {};

            var refresh_attachments_list = function() {
                $(attachments_list).find('.row').remove();
                for (var key in options.attachments) {
                    var mime = Object.keys(options.attachments[key])[0];
                    var deleted = key in to_delete;

                    // This ensures the current value of key is captured since
                    // javascript only has function scope
                    var btn;
                    // Trash/restore button
                    (function(){
                        var _key = key;
                        btn = $('<button>')
                            .addClass('btn btn-default btn-xs')
                            .css('display', 'inline-block');
                        if (deleted) {
                            btn.attr('title', i18n.msg._('Restore'))
                               .append(
                                   $('<i>')
                                   .addClass('fa fa-plus')
                               );
                            btn.click(function() {
                                delete to_delete[_key];
                                refresh_attachments_list();
                            });
                        } else {
                            btn.attr('title', i18n.msg._('Delete'))
                               .addClass('btn-danger')
                               .append(
                                   $('<i>')
                                   .addClass('fa fa-trash')
                               );
                            btn.click(function() {
                                to_delete[_key] = true;
                                refresh_attachments_list();
                            });
                        }
                        return btn;
                    })();
                    var row = $('<div>')
                        .addClass('col-md-12 att_row')
                        .append(
                            $('<div>')
                            .addClass('row')
                            .append(
                                $('<div>')
                                .addClass('att-name col-xs-4')
                                .text(key)
                            )
                            .append(
                                $('<div>')
                                .addClass('col-xs-4 text-muted')
                                .text(mime)
                            )
                            .append(
                                $('<div>')
                                .addClass('item-buttons pull-right')
                                .append(btn)
                            )
                        );
                    if (deleted) {
                        row.find('.att-name')
                           .css('text-decoration', 'line-through');
                    }

                    attachments_list.append($('<div>')
                        .addClass('list_item row')
                        .append(row)
                    );
                }
            };
            refresh_attachments_list();
        }

        var dialogform = $('<div/>')
            .attr('title', i18n.msg._('Edit attachments'))
            .append(message)
            .append('<br />')
            .append(attachments_list);
        var title_msg;
        if ( options.name === "Notebook" ) {
        	title_msg = i18n.msg._("Edit Notebook Attachments");
        } else {
        	title_msg = i18n.msg._("Edit Cell Attachments");
        }
        var modal_obj = modal({
            title: title_msg,
            body: dialogform,
            buttons: {
                Apply: { class : "btn-primary",
                    click: function() {
                        for (var key in to_delete) {
                            delete options.attachments[key];
                        }
                        options.callback(options.attachments);
                    }
                },
                Cancel: {}
            },
            notebook: options.notebook,
            keyboard_manager: options.keyboard_manager,
        });
    };

    var insert_image = function (options) {
        var message =
            i18n.msg._("Select a file to insert.");
        var file_input = $('<input/>')
            .attr('type', 'file')
            .attr('accept', 'image/*')
            .attr('name', 'file')
            .on('change', function(file) {
                var $btn = $(modal_obj).find('#btn_ok');
                if (this.files.length > 0) {
                    $btn.removeClass('disabled');
                } else {
                    $btn.addClass('disabled');
                }
            });
        var dialogform = $('<div/>').attr('title', i18n.msg._('Edit attachments'))
            .append(
                $('<form id="insert-image-form" />').append(
                    $('<fieldset/>').append(
                        $('<label/>')
                        .attr('for','file')
                        .text(message)
                        )
                        .append($('<br/>'))
                        .append(file_input)
                    )
            );
        var modal_obj = modal({
            title: i18n.msg._("Select a file"),
            body: dialogform,
            buttons: {
                OK: {
                    id : 'btn_ok',
                    class : "btn-primary disabled",
                    click: function() {
                        options.callback(file_input[0].files[0]);
                    }
                },
                Cancel: {}
            },
            notebook: options.notebook,
            keyboard_manager: options.keyboard_manager,
        });
    };

    
    var dialog = {
        modal : modal,
        kernel_modal : kernel_modal,
        edit_metadata : edit_metadata,
        edit_attachments : edit_attachments,
        insert_image : insert_image
    };

    return dialog;
});