Exemplo n.º 1
0
    def scripts(self):
        """Returns the scripts that should be imported."""

        scripts = ["vendors/json2/json2.js", "js/bibeditmulti.js"]

        result = ""
        for script in scripts:
            result += '<script type="text/javascript" src="%s/%s">' \
            '</script>\n' % (CFG_SITE_URL, auto_version_url(script))

        return result
Exemplo n.º 2
0
    def tmpl_styles(self):
        """Defines the local CSS styles and javascript used in the plugin"""

        styles = """
        <style type="text/css">

        .mandatory_field{
            color:#ff0000
        }
        .italics{
            font-style:italic
        }
        .italics_small{
            font-style:italic;
            font-size: 0.9em;
        }

        .clean_ok{
            border:solid 1px #349534;
            background:#C9FFCA;
            color:#008000;
            font-size:14px;
            font-weight:bold;
            padding:4px;
            text-align:center;
            width: 650px;
        }

        .clean_error{
            border:solid 1px #CC0000;
            background:#F7CBCA;
            color:#CC0000;
            font-size:14px;
            font-weight:bold;
            padding:4px;
            text-align:center;
            width: 650px;
        }

        #content {width:750px; font:90.1% arial, sans-serif;}

        .uploadform {margin:0 0 1em 0}

        .uploadform div {margin:0.5em 0}
        .uploadform fieldset {border:1px solid #657; padding:0.8em 1em; margin:2em 10px}

        #docuploadform {margin:0 0 1em 0}

        #docuploadform div {margin:0.5em 0}
        #docuploadform fieldset {border:1px solid #657; padding:0.8em 1em; margin:2em 10px}

        #error_div {color: red; font-style: bold; }

        div.ui-datepicker{
            font-size:12px;
        }

        span.red{
            color:#df0000;
        }
        span.green{
            color:#060;
            background: transparent;
        }
        span.yellow{
            color:#9f9b00;
        }

        #info_box{
            border: 3px black solid;
            border-width: thin;
            width: 750px;
        }

        img.img_link {
            border-style: none;
        }

        fieldset label {
            float: left;
            width: 150px;
        }

        label.nowidth {
            width: auto;
        }

        .batchuploader_error {
            max-width: 650px;
            max-height: 326px;
            border:solid 1px #CC0000;
            background:#F7CBCA;
            overflow: auto;
        }

        #batchuploader_error_list{
            list-style-type: none;
            padding-left: 10px;
        }

        #batchuploader_error_list li{
            margin-bottom: 10px;
        }
        </style>

        """

        styles += """
        <link type="text/css" href="%(site_url)s/img/jquery-ui.css" rel="stylesheet" />
        <script type="text/javascript">
            function clearText(field){
                if (field.value == field.defaultValue){
                    field.value = '';
                }
            }
            function defText(field){
                if (field.value == ''){
                    field.value = field.defaultValue;
                }
            }
        </script>
        <script type="text/javascript" src="%(site_url)s/js/jquery-ui.min.js"></script>
        <script type="text/javascript" src="%(site_url)s/%(script)s"></script>
        """ % {'site_url':CFG_SITE_URL,
               'script': auto_version_url(
                   url_for('uploader.static', filename="js/uploader/batchuploader.js"))}

        return styles
Exemplo n.º 3
0
    def tmpl_styles(self):
        """Defines the local CSS styles and javascript used in the plugin"""

        styles = """
        <style type="text/css">

        .mandatory_field{
            color:#ff0000
        }
        .italics{
            font-style:italic
        }
        .italics_small{
            font-style:italic;
            font-size: 0.9em;
        }

        .clean_ok{
            border:solid 1px #349534;
            background:#C9FFCA;
            color:#008000;
            font-size:14px;
            font-weight:bold;
            padding:4px;
            text-align:center;
            width: 650px;
        }

        .clean_error{
            border:solid 1px #CC0000;
            background:#F7CBCA;
            color:#CC0000;
            font-size:14px;
            font-weight:bold;
            padding:4px;
            text-align:center;
            width: 650px;
        }

        #content {width:750px; font:90.1% arial, sans-serif;}

        .uploadform {margin:0 0 1em 0}

        .uploadform div {margin:0.5em 0}
        .uploadform fieldset {border:1px solid #657; padding:0.8em 1em; margin:2em 10px}

        #docuploadform {margin:0 0 1em 0}

        #docuploadform div {margin:0.5em 0}
        #docuploadform fieldset {border:1px solid #657; padding:0.8em 1em; margin:2em 10px}

        #error_div {color: red; font-style: bold; }

        div.ui-datepicker{
            font-size:12px;
        }

        span.red{
            color:#df0000;
        }
        span.green{
            color:#060;
            background: transparent;
        }
        span.yellow{
            color:#9f9b00;
        }

        #info_box{
            border: 3px black solid;
            border-width: thin;
            width: 750px;
        }

        img.img_link {
            border-style: none;
        }

        fieldset label {
            float: left;
            width: 150px;
        }

        label.nowidth {
            width: auto;
        }

        .batchuploader_error {
            max-width: 650px;
            max-height: 326px;
            border:solid 1px #CC0000;
            background:#F7CBCA;
            overflow: auto;
        }

        #batchuploader_error_list{
            list-style-type: none;
            padding-left: 10px;
        }

        #batchuploader_error_list li{
            margin-bottom: 10px;
        }
        </style>

        """

        styles += """
        <link type="text/css" href="%(site_url)s/vendors/jquery-ui/jquery-ui.css" rel="stylesheet" />
        <script type="text/javascript">
            function clearText(field){
                if (field.value == field.defaultValue){
                    field.value = '';
                }
            }
            function defText(field){
                if (field.value == ''){
                    field.value = field.defaultValue;
                }
            }
        </script>
        <script type="text/javascript" src="%(site_url)s/vendors/jquery-ui/jquery-ui.min.js"></script>
        <script type="text/javascript" src="%(site_url)s/%(script)s"></script>
        """ % {'site_url':CFG_SITE_URL,
               'script': auto_version_url(
                   url_for('uploader.static', filename="js/uploader/batchuploader.js"))}

        return styles
Exemplo n.º 4
0
    def index(self, req, form):
        """Handle all BibMerge requests.
        The responsibilities of this functions are:
        * JSON decoding and encoding.
        * Redirection, if necessary.
        * Authorization.
        * Calling the appropriate function from the engine.
        """
        # If it is an Ajax request, extract any JSON data.
        ajax_request, recid1, recid2 = False, None, None
        argd = wash_urlargd(form, {'ln': (str, CFG_SITE_LANG)})
        if 'jsondata' in form:
            json_data = json.loads(str(form['jsondata']))
            # Deunicode all strings (Invenio doesn't have unicode
            # support).
            json_data = json_unicode_to_utf8(json_data)
            ajax_request = True
            json_response = {}
            try:
                if json_data.has_key('recID1'):
                    recid1 = int(json_data['recID1'])
                    json_data['recID1'] = recid1
                if json_data.has_key('recID2'):
                    if json_data.get('record2Mode') == "recid":
                        recid2 = int(json_data['recID2'])
                        json_data['recID2'] = recid2
            except ValueError:
                json_response.update({
                    'resultCode': 1,
                    'resultText': 'Invalid record ID!'
                })
                return json.dumps(json_response)
            if json_data.has_key("duplicate"):
                if json_data.get('record2Mode') == "recid":
                    json_data["duplicate"] = int(json_data["duplicate"])

        # Authorization.
        user_info = collect_user_info(req)
        if user_info['email'] == 'guest':
            # User is not logged in.
            if not ajax_request:
                # Do not display the introductory recID selection box to guest
                # users (as it used to be with v0.99.0):
                auth_code, auth_message = acc_authorize_action(
                    req, 'runbibmerge')
                referer = '/merge/'
                return page_not_authorized(req=req,
                                           referer=referer,
                                           text=auth_message,
                                           navtrail=navtrail)
            else:
                # Session has most likely timed out.
                json_response.update({
                    'resultCode': 1,
                    'resultText': 'Error: Not logged in'
                })
                return json.dumps(json_response)

        elif self.recid:
            # Handle RESTful call by storing recid and redirecting to
            # generic URL.
            redirect_to_url(
                req, '%s/%s/merge/' % (CFG_SITE_SECURE_URL, CFG_SITE_RECORD))

        if recid1 is not None:
            # Authorize access to record 1.
            auth_code, auth_message = acc_authorize_action(
                req,
                'runbibmerge',
                collection=guess_primary_collection_of_a_record(recid1))
            if auth_code != 0:
                json_response.update({
                    'resultCode':
                    1,
                    'resultText':
                    'No access to record %s' % recid1
                })
                return json.dumps(json_response)
        if recid2 is not None:
            # Authorize access to record 2.
            auth_code, auth_message = acc_authorize_action(
                req,
                'runbibmerge',
                collection=guess_primary_collection_of_a_record(recid2))
            if auth_code != 0:
                json_response.update({
                    'resultCode':
                    1,
                    'resultText':
                    'No access to record %s' % recid2
                })
                return json.dumps(json_response)

        # Handle request.
        uid = getUid(req)
        if not ajax_request:
            # Show BibEdit start page.
            body, errors, warnings = perform_request_init()

            scripts = ["vendors/json2/json2.js", "js/merger/engine.js"]
            metaheaderadd = ""
            for script in scripts:
                metaheaderadd += '<script type="text/javascript" src="%s/%s"></script>' % (
                    CFG_SITE_URL, auto_version_url(script))

            return page(title='Record Merger',
                        metaheaderadd=metaheaderadd,
                        body=body,
                        errors=errors,
                        warnings=warnings,
                        uid=uid,
                        language=argd['ln'],
                        navtrail=navtrail,
                        lastupdated=__lastupdated__,
                        req=req)
        else:
            # Handle AJAX request.
            json_response = perform_request_ajax(req, uid, json_data)
            return json.dumps(json_response)
Exemplo n.º 5
0
    def index(self, req, form):
        """Handle all BibMerge requests.
        The responsibilities of this functions are:
        * JSON decoding and encoding.
        * Redirection, if necessary.
        * Authorization.
        * Calling the appropriate function from the engine.
        """
        # If it is an Ajax request, extract any JSON data.
        ajax_request, recid1, recid2 = False, None, None
        argd = wash_urlargd(form, {'ln': (str, CFG_SITE_LANG)})
        if 'jsondata' in form:
            json_data = json.loads(str(form['jsondata']))
            # Deunicode all strings (Invenio doesn't have unicode
            # support).
            json_data = json_unicode_to_utf8(json_data)
            ajax_request = True
            json_response = {}
            try:
                if json_data.has_key('recID1'):
                    recid1 = int(json_data['recID1'])
                    json_data['recID1'] = recid1
                if json_data.has_key('recID2'):
                    if json_data.get('record2Mode') == "recid":
                        recid2 = int(json_data['recID2'])
                        json_data['recID2'] = recid2
            except ValueError:
                json_response.update({'resultCode': 1, 'resultText': 'Invalid record ID!'})
                return json.dumps(json_response)
            if json_data.has_key("duplicate"):
                if json_data.get('record2Mode') == "recid":
                    json_data["duplicate"] = int(json_data["duplicate"])

        # Authorization.
        user_info = collect_user_info(req)
        if user_info['email'] == 'guest':
            # User is not logged in.
            if not ajax_request:
                # Do not display the introductory recID selection box to guest
                # users (as it used to be with v0.99.0):
                auth_code, auth_message = acc_authorize_action(req, 'runbibmerge')
                referer = '/merge/'
                return page_not_authorized(req=req, referer=referer,
                                           text=auth_message, navtrail=navtrail)
            else:
                # Session has most likely timed out.
                json_response.update({'resultCode': 1,
                                      'resultText': 'Error: Not logged in'})
                return json.dumps(json_response)

        elif self.recid:
            # Handle RESTful call by storing recid and redirecting to
            # generic URL.
            redirect_to_url(req, '%s/%s/merge/' % (CFG_SITE_SECURE_URL,
                                                   CFG_SITE_RECORD))

        if recid1 is not None:
            # Authorize access to record 1.
            auth_code, auth_message = acc_authorize_action(req, 'runbibmerge',
                collection=guess_primary_collection_of_a_record(recid1))
            if auth_code != 0:
                json_response.update({'resultCode': 1, 'resultText': 'No access to record %s' % recid1})
                return json.dumps(json_response)
        if recid2 is not None:
            # Authorize access to record 2.
            auth_code, auth_message = acc_authorize_action(req, 'runbibmerge',
                collection=guess_primary_collection_of_a_record(recid2))
            if auth_code != 0:
                json_response.update({'resultCode': 1, 'resultText': 'No access to record %s' % recid2})
                return json.dumps(json_response)

        # Handle request.
        uid = getUid(req)
        if not ajax_request:
            # Show BibEdit start page.
            body, errors, warnings = perform_request_init()

            scripts = ["vendors/json2/json2.js", "js/merger/engine.js"]
            metaheaderadd = ""
            for script in scripts:
                metaheaderadd += '<script type="text/javascript" src="%s/%s"></script>' % (CFG_SITE_URL, auto_version_url(script))

            return page(title         = 'Record Merger',
                        metaheaderadd = metaheaderadd,
                        body          = body,
                        errors        = errors,
                        warnings      = warnings,
                        uid           = uid,
                        language      = argd['ln'],
                        navtrail      = navtrail,
                        lastupdated   = __lastupdated__,
                        req           = req)
        else:
            # Handle AJAX request.
            json_response = perform_request_ajax(req, uid, json_data)
            return json.dumps(json_response)