QString TPrototypeAjaxHelper::periodicalUpdateFunction(const QUrl &url, const QString &id, UpdateBehavior behavior, const TOption &options, bool evalScripts, int frequency, int decay, const QString &jsCondition) const { QString string; if (!jsCondition.isEmpty()) { string.append("if (").append(jsCondition).append(") { "); } string += QLatin1String("new Ajax.PeriodicalUpdater(\'"); string += id; string += QLatin1String("', '"); string += url.toString(); string += QLatin1String("', { "); // Appends 'insertion' parameter if (behavior != Replace) { string += behaviorHash()->value(behavior); } // Appends ajax options string += optionsToString(options); string += QLatin1String(", evalScripts:"); string += (evalScripts) ? QLatin1String("true") : QLatin1String("false"); string += QLatin1String(", frequency:"); string += QString::number(frequency); string += QLatin1String(", decay:"); string += QString::number(decay); string += QLatin1String(" });"); if (!jsCondition.isEmpty()) { string += QLatin1String(" }"); } return string; }
static QScriptValue qscript_options(QScriptContext *ctx, QScriptEngine *) { static QHash<QString, int> stringToFlagHash; if (stringToFlagHash.isEmpty()) { stringToFlagHash["strict"] = 1; stringToFlagHash["werror"] = 2; stringToFlagHash["atline"] = 4; stringToFlagHash["xml"] = 8; } QScriptValue callee = ctx->callee(); int opts = callee.data().toInt32(); QString result = optionsToString(opts); for (int i = 0; i < ctx->argumentCount(); ++i) opts |= stringToFlagHash.value(ctx->argument(0).toString()); callee.setData(opts); return result; }
QString TPrototypeAjaxHelper::requestFunction(const QUrl &url, const TOption &options, const QString &jsCondition) const { QString string; if (!jsCondition.isEmpty()) { string.append("if (").append(jsCondition).append(") { "); } string += QLatin1String("new Ajax.Request(\'"); string += url.toString(); string += QLatin1String("', { "); string += optionsToString(options); string += QLatin1String(" });"); if (!jsCondition.isEmpty()) { string += QLatin1String(" }"); } return string; }